php php代码和htaccess中的会话超时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5206061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
session timeout in php code and in htaccess?
提问by Prashant
What we use to set the session time out in php. I found following:
我们用来在 php.ini 中设置会话超时的方法。我发现以下内容:
ini_set(session.cookie_lifetime, 3600);
ini_set(session.gc_maxlifetime, 3600);
Is it right way to set timeout for session in php? Or is there any way we can set the time out in htaccess file?
在 php 中为会话设置超时是正确的方法吗?或者有什么方法可以在 htaccess 文件中设置超时时间?
Maybe its a simple question, but I am not really able to get the answer, even tried on SO, Google and php.net but no straight solutions or code for this.
也许这是一个简单的问题,但我真的无法得到答案,甚至尝试过 SO、Google 和 php.net 但没有直接的解决方案或代码。
回答by Prashant
I have resolved this issue by adding following code in my .htaccess
file.
我通过在我的.htaccess
文件中添加以下代码解决了这个问题。
<IfModule mod_php5.c>
#Session timeout
php_value session.cookie_lifetime 1200
php_value session.gc_maxlifetime 1200
</IfModule>
Thanks!
谢谢!
回答by Hamid
You can set the lifetime value to 0
您可以将生命周期值设置为 0
session.cookie_lifetime 1200
session.cookie_lifetime 1200
session.cookie_lifetime
specifies the lifetime of the cookie in seconds which is sent to the browser.
session.cookie_lifetime
指定发送到浏览器的 cookie 的生命周期(以秒为单位)。
The value 0 means "until the browser is closed."
值 0 表示“直到浏览器关闭”。
session.gc_maxlifetime 1440
session.gc_maxlifetime 1440
session.gc_maxlifetime
specifies the number of seconds after which data will be seen as "garbage" and potentially cleaned up. Garbage collection may occur during session start
session.gc_maxlifetime
指定数据将被视为“垃圾”并可能被清理的秒数。会话开始期间可能会发生垃圾收集