2012-03-28 140 views
56

默认情况下,PHP会话是否超时?即,如果没有任何编码,用户最终会在一段时间不活动后“退出”?PHP会话默认超时

+4

的可能的复制[在PHP扩展会话超时(http://stackoverflow.com/questions/514155/extending-session-timeout-in-php)和[我如何30分钟后到期PHP会话?](http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes)和[许多其他](http: //stackoverflow.com/search?q=php+session+timeout)。 – DaveRandom 2012-03-28 08:55:39

+1

感谢所有这些。我想要一个更直接的答案,因此这个问题! - upvoted – 2012-03-28 09:06:09

+3

有趣的是,所有答案都提到了“20分钟”和“1440秒”,没有人注意到1440秒实际上是24分钟。 – maligree 2012-07-09 08:55:05

回答

91

这取决于服务器配置或相关指令session.gc_maxlifetimephp.ini后会发生。

通常情况下,默认值为24分钟(1440秒),但您的虚拟主机可能已将默认值更改为其他值。

3

是的,通常情况下,会话将在PHP 20分钟后结束。

7

是的,这就是通常1440s(24分钟)

+1

24或20分钟.. – Mani 2013-05-07 05:03:11

+1

@Mani什么时候是1440秒20分? – kojow7 2017-09-18 21:11:50

15

你可以在你的web服务器上更改你的php-configuration。 在php.ini中搜索

session.gc_maxlifetime() 该值以秒为单位设置。

1

您可以设置会话超时在php.ini。默认值是1440秒

session.gc_maxlifetime = 1440 

; NOTE: If you are using the subdirectory option for storing session files 
;  (see session.save_path above), then garbage collection does *not* 
;  happen automatically. You will need to do your own garbage 
;  collection through a shell script, cron entry, or some other method. 
;  For example, the following script would is the equivalent of 
;  setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes): 
;   find /path/to/sessions -cmin +24 -type f | xargs rm