What is the default session expiration time in PHP?

流过昼夜 提交于 2019-12-12 19:16:49

问题


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?


回答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.




回答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.



来源:https://stackoverflow.com/questions/4233924/what-is-the-default-session-expiration-time-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!