I have to check out the session in each controller. If user is logged out then redirect to login page. How could i do it using hooks in codeigniter, so that i don't have to write session condition in each controller. Help me out.
I have following code in application/hooks/Authenticate.php
function __construct()
{
$this->CI =& get_instance();
}
function loginCheck()
{
if($this->session->userdata('role_id')=='' && $this->session->userdata('user_id')=='' && $this->session->userdata('client_id')==''){
redirect('login');
}
}
Following code in application/config/hooks.php
$hook['pre_controller'][] = array(
'class' => 'Authenticate',
'function' => 'loginCheck',
'filename' => 'authenticate.php',
'filepath' => 'hooks/authenticate',
'params' => array()
);
When i logout and press browser back button,it again takes me to the login section. It seems that the session is not destroyed properly.