0
votes

I have an strange problem with (latest) Codeigniter. I use the session class for my login. After login i store some userdata in the session.

I developed my application local and the login works fine. When the application was finished , i uploaded it to my webserver http://mijn.exova.nl/. The application worked fine for a day. But a day later the session are not stored after the login. I uploaded the code again from local but the problem still exist. Before the redirect the session still exist. After the redirect the session is empty.

Code:

Config settings session (are default)

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
$config['cookie_prefix']        = "";
$config['cookie_domain']    = "";
$config['cookie_path']  = "/";
$config['cookie_secure']    = FALSE;

Creation session (in library)

$this->CI->session->set_userdata('exova_login', true);
$this->CI->session->set_userdata('exova_userdata', $userdata);
$this->CI->session->set_userdata('exova_rollen', $rollen);
$this->CI->session->set_userdata('exova_school', $school);

Redirect (before session is oke, after the session is empty)

redirect(base_url());

Does somebody know why this problem occured? Thanks!

1
I have a similar problem with my application. However I know my mistake. Maybe you are doing the same?: When user is logging in I set some preferences. When user logs out I do not destroy the session. I just the the preferences empty (set_userdata('mypref',"")). When user tries to log in again it fails. Delete browser cache with all information and try to log in again... I do not know when your doing the redirect. Maybe it is a neccessary information?! - zuluk
Hello Zuluk. In my case the session are destroyed at the logout so thats not the problem. But thanks for your comment! - JelleP
All the code you have posted seems fine, it's probably going to be hard for anyone to help you without posting more code. Have you tried debugging it (echoing out values of variables/session before/during/after login?) Any errors in the logs? - Jeemusu

1 Answers

0
votes

It works again! The exact problem is unknown but when i removed all browser data it works again. I learned that it is very importend to set session not twice. I solved it by adding this:

if($this->CI->session->userdata('exova_login') == false){

arround the session set. Session will never be set twice and that ensured that problems like these can be avoided. Thanks for the comments.