简体   繁体   English

即使设置了较高的值,PHP会话超时也会提前发生

[英]PHP session timeout occurs early even though a higher value is set

I have added the following lines in my htaccess file : 我在htaccess文件中添加了以下几行:

php_value session.cookie_lifetime 14400
php_value session.gc_maxlifetime 14400

Also have added a php.ini file in the root directory with the following code : 还已经在根目录中添加了php.ini文件,其中包含以下代码:

session.gc_maxlifetime = 14400
session.cookie_lifetime = 14400

Also inside the php code have added the following lines : 同样在php代码内部添加了以下几行:

ini_set('session.cookie_lifetime',14400);
ini_set('session.gc_maxlifetime',14400);
setcookie("_lid", $lid, time() + 14400);

So basically the session should work for 4 hours. 因此,基本上该会话应该工作4个小时。 But it is getting timed out in about 24 mins or so which is the default timeout time in php. 但是它会在大约24分钟左右的时间内超时,这是php中的默认超时时间。

I may be missing something. 我可能会缺少一些东西。 Would be great if someone can provide some inputs. 如果有人可以提供一些意见,那就太好了。

Thanks 谢谢

I was having the exact same problem - the session.gc_maxlifetime & session.cookie_lifetime values were set but appeared to not be honoured... Then, I found a comment on an old thread which clearly needs a lot more recognition: 我遇到了完全相同的问题-设置了session.gc_maxlifetime和session.cookie_lifetime值,但似乎没有兑现……然后,我在一个旧线程上找到了一条注释,显然这需要更多的识别:

How do I expire a PHP session after 30 minutes? 30分钟后如何终止PHP会话?

Please note that at least two settings are crucial to setting the session time, and maybe three. 请注意,至少两个设置对于设置会话时间至关重要,也许三个。 The two certainly crucial ones are session.gc_maxlifetime and session.cookie_lifetime (where 0 is not the same as some long number). 两个绝对重要的参数是session.gc_maxlifetime和session.cookie_lifetime(其中0与一些长数字不同)。 For complete, 100% certainty of allowing long times, it may also be necessary to set the session.save_path, due to varying OS-controled cleanup time on the /tmp directory where session files get stored by default. 为了完全100%地确定允许长时间运行,可能还需要设置session.save_path,这是由于/ tmp目录上默认存储会话文件的操作系统控制的清除时间不同。 – @Kzqai Apr 7 '11 at 8:04 – @Kzqai 2011年4月7日在8:04

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM