简体   繁体   English

在运行php上增加时间会话超时

[英]Increment time session time out on running php

How can i increment the time of the session time out once the session has started? 会话开始后,如何增加会话超时时间? I set in the php.ini file: 我在php.ini文件中设置:

session.gc_maxlifetime = 3600

but i need to keep alive the session while the user has the page open. 但是我需要在用户打开页面的同时保持会话状态。

You could do it like this 你可以这样

ini_set("session.gc_maxlifetime", 3600);

Look here for more info: http://us2.php.net/ini_set 在这里查看更多信息: http : //us2.php.net/ini_set

If you really want a different timeout for each user, then I would do: ini_set(session.gc_maxlifetime, 43200); // 12 hours 如果您真的想为每个用户设置不同的超时时间,那么我应该这样做: ini_set(session.gc_maxlifetime, 43200); // 12 hours ini_set(session.gc_maxlifetime, 43200); // 12 hours As your max range then say: ini_set(session.gc_maxlifetime, 43200); // 12 hours作为最大范围,然后说:

$customEndTime = (rand(0, 4320) * 10) + time(); // max rand is usually 32767
$_SESSION['endTime'] = $customEndTime;

When you go to check your session variables, just add that check in there and if the customEndTime > time() , then reset the users session using session_destroy(); 当您检查会话变量时,只需在其中添加检查内容,并检查customEndTime > time() ,然后使用session_destroy();重置用户会话即可session_destroy();

You can of course increase 43200 to whatever you need. 当然,您可以根据需要增加43200。 To calculate it, say: 60*60*$maxNumberOfHours 要进行计算,请说: 60*60*$maxNumberOfHours

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

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