2012-03-28 180 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