What is the default session expiration time in PHP?

16,520

Solution 1

The default value of session.gc_maxlifetime is 1440 seconds. So the garbage collector assumes a session to be expired when the last modification was at least 1440 seconds ago.

Note that when using a cookie for the session ID it might have a different lifetime. The default value 0 of session.cookie_lifetime makes the cookie a session cookie, that means it expires when the browser session is ended (i.e. the browser is closed).

See also my answer on How do I expire a PHP session after 30 minutes? for further information on session expiration.

Solution 2

From php.ini:

; Lifetime in seconds of cookie or, if 0, until browser is restarted. ; http://php.net/session.cookie-lifetime session.cookie_lifetime = 0

That would be the default if I'm not mistaken. Either set it to zero (if it's not already set) or just use another cookie.

Share:
16,520
Bill
Author by

Bill

Updated on June 15, 2022

Comments

  • Bill
    Bill almost 2 years

    I have a web application that pings a database every minute or so to check for new entries. The page is designed to not really have any interaction with... You just keep it open and it displays things. The page is password protected, and the site can be up for a coupe days without anyone clicking in the web browser or anything. I've found after it's up for like a day or so it stops checking the database (through an Ajax request) and then if you refresh the page manually it brings you to the login page again. I'm assuming that's because the session which has the login information expires. I never set an expiration time, but does PHP automatically destroy the sessions after a certain amount of time? What do I do to fix this?

    Thanks

    Thanks for all the replies... Is there a way to set the session to never expire with out just changing the PHP settings themselves?