Reputation: 1469
I have a cookie that appears to be getting created correctly, listed in chrome as
Created: Tuesday, January 22, 2013 4:17:01 PM
Expires: Thursday, May 2, 2013 5:17:22 PM
I see the session file in the tmp folder on my server, and I can close and re-open the browser and remain logged in. However, after several hours of inactivity, the session file appears to get deleted from the tmp folder.
I solved a previous problem where the session was getting overwritten (session file still existed, but size was 0 bytes) because a script called by jquery function was not preserving the session data. However, in this case the session file disappears.
How can I fix this problem?
Upvotes: 1
Views: 1123
Reputation: 18260
Every session has a limited lifetime. In PHP this lifetime can be set by
ini_set( 'session.gc_maxlifetime', seconds );
session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor).
http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime
Dont set this to very high values (days or months) If you want to auto-login your users, save a token into a users cookie and create a new session when the old one is gone.
Might want to read this Designing a secure auto login cookie system in PHP
and this Creating a secure login using sessions and cookies in PHP
Upvotes: 1