Project Tutorials
Introduction Directory Structure Project Setup Remove index.php using htaccess Change Default Controller CSS Add in Project Create Login Page Design Validation on Login Login with Database Flashdata on Login Display Username after Login Logout Design Dashboard Page List user data form database Insert Data Flash message show if data inserted Delete data from datebase Edit data from datebase Active Inactive user status Show active users detail on home page Image Upload Edit Image View Image on Home PageLogout
In this tutorial, we will learn how to create logout.
Step 1: You have to go to your Login Controller and create a logout function there. With the help of which you can log out.
eg :
public function logout()
{
$this->session->unset_userdata('id');
$this->session->sess_destroy();
return redirect('login');
}
unset : to unset a session variable.
eg : $this->session->sess_destroy();
destroy : to destroy whole the session.
eg: $this->session->sess_destroy();
Step 2 : Now you have to go to your dashboard page and pass the link of the logout function on your logout button and we will also check if the user has logged in then show logout button otherwise login.
eg :
<?php if($this->session->userdata('id')){ ?>
//passing logout link
<a class="nav-link" href="<?php echo base_url(); ?>login/logout">Logout</a>
<?php }else{ ?>
<a class="nav-link" href="<?php echo base_url(); ?>login">Login</a>
<?php } ?>
Step 3 : We will also check if the user has logged in. So he could not go to the dashboard page without login. For this, we will create a constructor in Dashboard controller, in which we will check that if the user is not logged in then he cannot return to the dashboard page untill he login.
public function __construct()
{
parent::__construct();
if(!$this->session->userdata('id')){
return redirect('login');
}
}
Result :
Source Code:
Codeigniter tutorial for beginners
In this project. We are providing you, how to create small project in Codeign....
Source CodeElevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date