2016-03-31

Simple Tutorial : Codeigniter Login System Tutorial Without Database Connection

Simple Tutorial : Codeigniter Login System Tutorial Without Database Connection

level : easy 


Did you know? All of systems has the security to block uninvited user for come. Just some users have key (like username, password, or captcha) allowed. Today, we will learn about login system in PHP with Codeigniter framework but you can run without any database connection. - Only for learning, not for creating big system - It will really simple. You just need files in your Codeigniter controller and views. It will needs login.php and logout.php in controller and login.php  and admin.php in views.

Steps:
1. Preparing Codeigniter framework
2. Create login.php in your controller
3. Create logout.php in your controller
4. Create login.php in your views
5. Create admin.php in your views
6. Run program

Information: we will create login system with "session" to save temporary data of user

Create login.php in Controller
public function index() {
 $this->load->view('login');

}

public function login() {

 $this->load->library('session');
 $this->load->library('form_validation');
 $this->load->helper('url'); 
 $this->form_validation->set_rules('username','Username',
'trim|required');
 $this->form_validation->set_rules('password','Password',
'trim|required|md5');
 if($this->form_validation->run()==false){
  $this->index();
 }else{
  $user_session=array(
   'Username'      => $this->input->post('username'),
   'Password'      => $this->input->post('password'),
   'is_logged_in'  => 1
  );
  $this->session->set_userdata('userlogin',$user_session);
  $this->admin();
 }

}

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

}

Create logout.php in Controller
public function index() {

 //$this->load->view('logout');
 $this->load->view('login'); 

}

public function logout() {

 $this->load->library('session');
 $this->session->unset_userdata('userlogin');
 $this->index();
 
}

Create login.php in Views
<form class="form-horizontal" role="form" action=
"<?php echo 'http://localhost/answers/index.php/login/
login'; ?>" method="post">
 <div class="form-group">
   <label class="control-label col-sm-2" for="username"
>Username:</label>
   <div class="col-sm-10">
  <input type="username" class="form-control" id="username"
 name="username" placeholder="Enter username">
   </div>
 </div>
 <div class="form-group">
   <label class="control-label col-sm-2" for="pwd">
Password:</label>
   <div class="col-sm-10">          
  <input type="password" class="form-control" id="password"
 name="password" placeholder="Enter password">
   </div>
 </div>
 <div class="form-group">        
   <div class="col-sm-offset-2 col-sm-10">
  <div class="checkbox">
    <label><input type="checkbox"> Remember 
me</label>
  </div>
   </div>
 </div>
 <div class="form-group">        
   <div class="col-sm-offset-2 col-sm-10">
  <button type="submit" class="btn btn-default">
Login</button>
   </div>
 </div>
</form>

Create admin.php in Views
<form class="navbar-form navbar-right" role=
"search" action="<?php echo 'http://localhost/answers
/index.php/logout/logout'; ?>">
 <button type="submit" class="btn btn-default">
Logout</button>
</form>
<h2>Welcome to the system, 
<?php 
 $this->load->library('session');
 $login_session = $this->session->userdata('userlogin');
 //$username = $this->session->userdata('userlogin');
 echo $login_session['Username'];
?>
</h2>
Run program

- Login Page -
Codeigniter Login System Tutorial Without Database Connection

Write your url address, example http://localhost/answers/index.php/login/login to display your login form.

- Admin Page -
Codeigniter Login System Tutorial Without Database Connection







We will get the greeting and also mention our name / username. Then if you click your logout button it will back into login page


Those files from google drive. You can download the one at :
Link download1 (short program)
Link download2  (complete files)
Share This

2 comments:

  1. CodeIgniter is gaining popularity these days. It is easier, faster and more reliable as compared to other frameworks. Kanhasoft is leading CodeIgniter Development Company in India which has successfully completed many CodeIgniter Web Development projects. Visit our site.

    ReplyDelete
  2. Explicitphp >>>>> Download Now

    >>>>> Download Full

    Explicitphp >>>>> Download LINK

    >>>>> Download Now

    Explicitphp >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete

About Us

Like Us

Labels

Designed By Blogger Templates