Hello i am using post_controller hooks to validate user whether logged in or not But when validation fails i redirect user to login controller.... Now the problem is when it redirect to defaults controller post_controller hooks is called again and in this way infinite loop starts with redirection repeatedly. i want to call post_controller hook for every controller except login controller.... also is there way that i don't need to load session library again and again because, if user is logged in then it loads session library in post controller as well as via auto-load in config file... Here is my code
//Hooks
$hook['post_controller'] = array(
'class' => 'is_login',
'function' => 'index',
'filename' => 'is_login.php',
'filepath' => 'hooks'
);
//Is_Login Hook
class is_login {
function __construct(){
$this->CI =& get_instance();
if(!isset($this->CI->session)) //Check if session lib is loaded or not
$this->CI->load->library('session'); //If not loaded, then load it here
}
public function index()
{
$login_id = $this->CI->session->userdata('login_id');
$login_flag = $this->CI->session->userdata('logged_in');
if ($login_flag != TRUE || $login_id == "")
{
redirect(site_url().'/welcome_login', 'refresh');
}
}
}