Marc Blase

Max lifetime for a PHP session

I was receiving complaints about a multi- page form I developed for a client. I couldn’t replicate the error, so I set out to research the ins-and-outs of PHP sessions. I’ve come to find out that any session data that is set will expire in the default setting of 24 minutes (1440 seconds) which is set in php.ini. To extend that time you have to either update the php.ini file (not a good idea) or update your script with ini_set() which will set the max lifetime for a session for your script. Simply call it on all the pages of your script with:

< ?php ini_set("session.gc_maxlifetime", "5400"); ?>

Now your users can spend, in my case, 90 minutes on the page without their session data expiring.

Published on July 11, 2011