Skip to main content

Codeigniter initial setup


1. Download Latest version of codeignitor from "https://codeigniter.com/".

OR

Download from link below :

https://drive.google.com/open?id=1K_VZEu2idorUS3vxHiIB5bIzIYt289kH

2. Extract .zip folder and rename it by project name.

3. Place that unziped folder into localhost htdocs folder.

4. Open project in browser as "localhost/projectname", Page with "Welcome to Codeignitor" will appears.

5. Open config.php inside application > config > config.php and set base URL "http://localhost/projectname".

6. Open database.php inside application > config > database.php and set hostname,username,password,database.

7. Create database and tables using localhost/phpmyadmin if not created.

8. Go to application > controller and create new file "Auth.php" as well as go to application > model and create new file

Auth_model.php

9. Write this code inside Auth_model.php

class Auth_model extends CI_Model
{
public function __construct()
{
parent:: __construct();
}
}
10. Write this code inside application > controller > Auth.php

class Auth extends CI_Controller
{
public function login()
{
echo 'login page';
}
}

hit the url=> "localhost/__projectname__/index.php/auth/login" login page able to see.//please configure projectname correctly

11. Create new "assets" folder inside root directory and place all css, js, fonts inside it.

12. Now Go to application > views and create login.php as well as register.php.

13. On register.php change link for css and js as :

<link href="<?php echo base_url();?>assets/css/bootstrap.min.css" rel="stylesheet">
<script src="<?php echo base_url();?>assets/js/bootstrap.min.js" ></script>

Design registration form with

<?php if(isset($_SESSION['success'])) { ?>
<div class="alert alert-success"><?php echo $_SESSION['success'];?></div>
<?php } ?>

<?php echo validation_errors('<div class="alert alert-danger">','</div>'); ?> //write wherever want to display errors

<form action="" method="POST">--[Registration feilds]--<input type="submit" name="register">--</form>.

14. Open application > config > autoload.php and set :

$autoload['libraries']=array('database','session','form_validation');
$autoload['helper'] = array('html','url','form');

15. For Registration open application > controller > Auth.php and add new register function coded as :

public function register()
{
if(isset($_POST['register']))
{
$this->form_validation->set_rules('username','Username','required');//Repeat for every feild that needs to be validate.
$this->form_validation->set_rules('password','Confirm Password','required|min_length[5]|matches[password]');

if($this->form_validation->run() == TRUE)
{
echo "form validated";

//add user in database
$data = array(

'table_feildname1'=>$_POST['name1_post_by_form'];
'table_feildname1'=>$_POST['name1_post_by_form'];
'username'=>$_POST['username'];
'username'=>md5($_POST['password']);
'created_date'=>date('Y-m-d');

);

$this->db->insert('table_name',$data);
$this->session->set_flashdata("success","registered, can login now");

redirect("auth/register", "refresh");
}
}
//load view
$this->load->view('register');

}
16. Design Login form

<form action="" method="POST">--[Login feilds]--<input type="submit" name="login">--</form>.

17. For Login open application > controller > Auth.php and edit login function coded as :

public function login()
{
$this->form_validation->set_rules('username','Username','required');//Repeat for every feild that needs to be validate.
$this->form_validation->set_rules('password','Password','required|min_length[5]');

if($this->form_validation->run() == TRUE)
{
$username = $_POST['username'];
$password = md5($_POST['password']);

//check user in database
$this->db->select('*');
$this->db->from('table_name');
$this->db->where(array('username'=>$username, 'password'=>$password));
$query = $this->db->get();
$user = $query->row();
//if user exists
if($user->email)
{
//temporary message
$this->session->set_flashdata("success","logged in");
$_SESSION['user_logged']=TRUE;
$_SESSION['username'] = $user->username;

//redirect to profile page
redirect("user/profile","refresh");

} else {
$this->session->set_flashdata("error","account doen't exists");
redirect("auth/login","refresh");
}

}

$this->load->view('login');
}

18. Go to application > controller create new controller User.php and code as below:

class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
if(!isset($_SESSION['user_logged']))//if(isset($_SESSION['user_logged'])==FALSE)
{
$this->session->set_flashdata("error","Please login to view this page");
redirect("auth/login");
}
}

public function profile()
{
$this->load->view('profile');
}
}

19. Go to application > views and add new file "profile.php".

<h1>Profile page </h1>
<?php if(isset($_SESSION['success'])) { ?>
<div class="alert alert-success"><?php echo $_SESSION['success'];?></div>
<?php } ?>

<a href="<?php echo base_url()?>index.php/auth/logout">Logout</a>

20. Go to application > controller > Auth.php and add logout function as coded:

public function logout()
{
unset($_SESSION);
session_destroy();
redirect("auth/login", "refresh");
}

Comments

Popular posts from this blog

SETUP REST API IN CI

1. Create Rest_controller.php inside controllers and paste code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); require APPPATH . '/libraries/API_Controller.php'; class Rest_controller extends API_Controller { public function __construct() { parent::__construct(); } public function index() { $this->api_return(             [ 'status' => true,                'result' => "Welcome to Testservices."             ],         200); } } ?> 2. Create api.php inside config and paste code : <?php defined('BASEPATH') OR exit('No direct script access allowed'); /**  * API Key Header Name  */ $config['api_key_header_name'] = 'X-API-KEY'; /**  * API Key GET Request Parameter Name  */ $config['api_key_get_name'] = 'key'; /**  * API Key POST Request Parameter Name ...

Array Difference, Radio Button Js,

$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("e"=>"red","f"=>"green","g"=>"blue"); $result=array_diff($a1,$a2); print_r($result); ______________________________________________________ <script type="text/javascript">  $(document).ready(function(){       $("input[type='radio']").click(function(){             var radioValue = $("input[name='duration']:checked").val();             if(radioValue){                 alert("Your are a - " + radioValue);             }         });  }); </script>   $(document).on("click", ".upappdesc", function(){ // alert($(this).data('id'));  var option = $(this).data("cat").split(",");  // alert($(this).data(...

KrutiDev To Unicode Conversion

http://wrd.bih.nic.in/font_KtoU.htm ___________________________________ <html> <head> <title>KrutiDev <=> Unicode Conversion</title> </title> <link rel="stylesheet" href="style.css">       <script src='script.js'></script> </head> <!--       body of the HTML starts here. one text box is provided each for input and output. --> <body bgcolor='#99CCFF'> <P style='text-align:center; font-family: Arial, Helvetica, sans-serif; font-size: 14pt; font-weight:bold; background-color: #FF6600; color: #FFFFFF'> Conversion between Krutidev-010 and Unicode क्रुतिदेव-०१० और यूनिकोड के बीच रूपांतरण </P> <form name="form1"> <p style='font-size:10pt'>क्रुतिदेव-०१० (Kruti Dev 010) फॉन्ट में टंकिट टेक्स्ट को "क्रुतिदेव-०१०" नामक टेक्स्ट बॉक्स में टाईप या पेस्ट करें तथा इसे यूनिकोड में रूपांतरित करने के लिए अधोमुख तीर वाल...