在 htaccess 中声明会话最大生存时间 [英] Declaring Session Max Life Time in htaccess

查看:38
本文介绍了在 htaccess 中声明会话最大生存时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们是否可以声明session.gc_maxlifetime.htaccess 中为一个特定项目而不是整个 Web 服务器设置?

I am wondering whether we can declare session.gc_maxlifetime setting in .htaccess for the one particular project instead of whole web server?

如果是这样,我们该怎么做?喜欢下面的代码吗?

If so, how can we do that? Like the following code?

php_value session.gc_maxlifetime 2000

我试过了,但没有用,我还在项目的同一目录中创建了一个 php.ini 文件,但也没有用.

I've tried it and it didn't work and also I created a php.ini file in the same directory of my project and it didn't work either.

谢谢.

推荐答案

是的,session.gc_maxlifetime 是 PHP_INI_ALL 设置,因此可以在 .htaccess 中覆盖:

Yes, session.gc_maxlifetime is a PHP_INI_ALL setting so it can be overidden in .htaccess:

php_value session.gc_maxlifetime 2000

还要确保 Apache 配置中的 条目支持覆盖:

Also make sure that <Directory> entry in your Apache configuration supports override:

AllowOverride Options

您也可能误解了此选项的用途.此选项不会设置会话的最长生命周期,它将设置垃圾收集器在会话无效时清理会话的时间量.这可以由很多因素决定,包括访问时间、修改时间、其他 INI 选项,例如 session.gc_probabilitysession.gc_divisor.

It also may be possible that you misunderstood the purpose of this option. This option will not set the maximum life time of a session, it will set the amount of time after which the garbage collector will clean the session if it's not valid. This can be determined by a lot of factors, including access times, modification times, other INI options such as session.gc_probability and session.gc_divisor.

如果您想限制会话生命周期,请使用适当的机制,如 如何在 30 分钟后使 PHP 会话过期.

If you want to limit a session life time, use a proper mechanism for that, as described by @Gumbo in How do I expire a PHP session after 30 minutes.

这篇关于在 htaccess 中声明会话最大生存时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆