I’m using CodeIgniter’s built in sessions, not PHP sessions (read more: http://codeigniter.com/user_guide/libraries/sessions.html). I also save the user’s session to a table in my database. I’m running into a problem where a user’s session data will be reset to default after a period of inactivity, when my intended action is for it to persist forever/until the user logs out/clears their cookies.
Here are my CodeIgniter application/config/config.php settings:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$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;
Theoretically, I figured that since sess_expiration is set to 0, it would persist until one of the listed actions above happened. Unfortunately, it looks like it just times out after maybe 30 minutes or so? I haven’t pinpointed that number, but the point is that it is way too short.
I have also read about how CI and AJAX calls may run into a bunch of problems. Although my website uses a lot of AJAX calls, the session will expire even if someone logs in once, doesn’t do anything, comes back in ~30 minutes and sees that they’re logged out!
EDIT: Just for future reference if anyone stumbles upon this topic: I am working on implementing a “remember me” feature instead. This will store a cookie in the user’s browser and will check it upon visiting the website. This is the proper way to do it as far as I can see rather than trying to make a session last indefinitely.
Take a look at sess_read() and sess_update() in /system/libraries/Session.php
Session expiration is checked with last_activity + sess_expiration < now
Probably you need to change the default value of $sess_expiration