Hello;
I am using CI 2.1.4.
Sometimes randomly users get logged out.
I see the cookie exists in the cookie tab and the expiry is in a month. But it keeps redirecting me to the login page and print_r($_SESSION) prints: Undefined variable: _SESSION
This is how I log them in:
PHP Code:
$newdata = array('username' => $data['member_details'][0]->first_name,'email' => $data['member_details'][0]->email, 'member_id' => $data['member_details'][0]->id, 'logged_in' => TRUE);
$this->session->set_userdata('logged_data', $newdata);
This is how I check if the user is logged in or not:
PHP Code:
public function logged()
{
$CI =& get_instance();
if(isset($CI->session->userdata['logged_data']['logged_in']))
{
$CI->logged = $CI->session->userdata['logged_data']['logged_in'];
$CI->header->check_account();
$CI->header->check_page_access();
return true;
}
if($this->logged!=TRUE)
{
if($CI->uri->segment(1)!='scan' && $CI->uri->segment(1)!='login' && $CI->uri->segment(1)!='forgot_password' && $CI->uri->segment(1)!='auth' && $CI->uri->segment(1)!='new_password' && $CI->uri->segment(1)!='signup' && $CI->uri->segment(1)!='forgot-password')
{
$newdata = array('back_url' => current_url());
$CI->session->set_userdata('logged_data', $newdata);
redirect(base_url('login'), 'location', 301);
}
return FALSE;
}
}
Config:
PHP Code:
*/
$config['sess_cookie_name'] = 'ci_session_web';
$config['sess_expiration'] = 2678400;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
Cookie tab shows this:
Code:
ci_session_tac_web:
a:4:{s:10:"session_id";s:32:"862a8cabffc1f3974f6e5ca4b5b29fe4";s:10:"ip_address";s:13:"10.217.27.240 "
;s:10:"user_agent";s:82:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:43.0) Gecko/20100101 Firefox
/43.0";s:13:"last_activity";i:1450843212;}96be95741a1cc547efc730b4498cae6a
Thank you