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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:37:50  来源:igfitidea点击:

session timeout in php code and in htaccess?

php

提问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 .htaccessfile.

我通过在我的.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_lifetimespecifies 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_maxlifetimespecifies 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指定数据将被视为“垃圾”并可能被清理的秒数。会话开始期间可能会发生垃圾收集