PHP 中默认的会话过期时间是多少?
我有一个 Web 应用程序,它每分钟左右 ping 一次数据库以检查新条目。该页面的设计目的是不与...进行任何交互。您只需将其保持打开状态即可显示内容。该页面受密码保护,并且该网站可以在没有任何人点击网络浏览器或任何其他内容的情况下正常运行。我发现在它运行一天左右后,它会停止检查数据库(通过 Ajax 请求),然后如果您手动刷新页面,它会再次带您进入登录页面。我假设这是因为具有登录信息的会话过期了。我从来没有设置过期时间,但是 PHP 会在一定时间后自动销毁会话吗?我该怎么做才能解决这个问题?
感谢
感谢所有回复...有没有一种方法可以将会话设置为永不过期,而无需更改 PHP 设置本身?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
session.gc_maxlifetime 是 1440 秒。因此,当最后一次修改至少在 1440 秒前时,垃圾收集器假定会话已过期。
请注意,当使用 cookie 作为会话 ID 时,它可能具有不同的 一生。 session.cookie_lifetime的默认值
0
使cookie成为会话cookie,这意味着它在浏览器会话结束(即浏览器关闭)时过期。另请参阅我对的回答如何让 PHP 会话在 30 分钟后过期? 有关会话过期的更多信息。
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.
来自 php.ini:
如果我没有记错的话,这将是默认值。将其设置为零(如果尚未设置)或仅使用另一个 cookie。
From php.ini:
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.