Hello guys i am using CodeIgniter Framework, i have a problem within after logout, the session is already destroyed and redirect to login form, and after redirecting to logi
I tired to implement this option but it doesn't works well. So i implement new logic on this.
Simply check is session is set in every main methods. Below code help you
In logout(define in controller)
function __construct()
{
parent::__construct();
ob_start(); # add this
}
public function logout()
{
$this->load->driver('cache');
$this->session->sess_destroy();
$this->cache->clean();
ob_clean();
redirect('home'); # Login form or some other page
}
In dashboard(Function)
public function home()
{
$logged_in = $this->session->userdata('logged_in');
if($logged_in != TRUE || empty($logged_in))
{
#user not logged in
$this->session->set_flashdata('error', 'Session has Expired');
redirect('user_logging'); # Login view
}
else
{
#user Logged in
$this->load->view("viewname",$data);
}
}
In Login(function)
$session = array(
'username' => $name,
'logged_in' => TRUE
);
$this->session->set_userdata($session);