Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter: User session keeps expiring

I'm using CodeIgniter, and I'm having a small issue with sessions. I've set 'sess_expiration' in config.php to 0 so that the user session will never expire, yet users -even myself- are still occasionally kicked out and asked to login again! (i'm storing sessions in the DB btw)

The way I validate a user's session is by basically checking if user_id (which I've previously stored in the session is TRUE or FALSE. If it's FALSE then it asks them to login again.

Any idea what could be forcing sessions to expire?

Appreciate your help :)

like image 505
KeyStroke Avatar asked Apr 22 '26 17:04

KeyStroke


2 Answers

If you're making AJAX requests in your app/site I think this may be the issue you are experiencing: https://github.com/EllisLab/CodeIgniter/issues/154

It seems to be a bug in how CI handles AJAX requests updating sessions.

like image 62
Ray Avatar answered Apr 24 '26 05:04

Ray


Try setting the session expire to some really large number. Try:

time()+(3600*24*365*5)

or

time()+157680000;

This session should last you 5 years.

like image 26
Chris McClellan Avatar answered Apr 24 '26 05:04

Chris McClellan