Codeigniter Session and Hook redirect making Loop redirect error - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Codeigniter Session and Hook redirect making Loop redirect error (/showthread.php?tid=60989) |
Codeigniter Session and Hook redirect making Loop redirect error - El Forum - 08-21-2014 [eluser]Unknown[/eluser] I m using Codeigniter. I have to check session is set for each page if not set then redirect to login page. i hve dont tht on login to home page using normal CI session but i want to use hooks for other pages how can i do it?? i have set $this->session->set_userdata("is_in_login_page",true); in Login controller when login page loaded soo hook wont check on if its login page=true once user login i set tht is_in_login_page to false when i navigate directly to others pages like It gives This page has Redirect Loop. and how should do idle timeout. i tried keeping update time in session thn calling ajax every 2 mins to check current time and last updated time. but as soon as ajax request made session value also becomes current time and difference =0 .if any1 knw has better way pls let me knw. I also tried to change session sess_time_to_update but no help either This is my hook code $hook['post_controller_constructor'][] = array( 'class' => 'Authenticate', 'function' => 'loginCheck', 'filename' => 'authenticate.php', 'filepath' => 'hooks', 'params' => array() ); class Authenticate { private $CI; 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 } function loginCheck() { date_default_timezone_set("Asia/Kolkata"); $session_userdata = $this->CI->session->userdata('logged_in'); if($this->CI->session->userdata('is_in_login_page')==true) { // It gives Error This webpage has a redirect loop redirect('login'); // it goes in redirect Loop } } } |