当用户处于活动状态时如何继续延长会话寿命? [英] How to keep extending session life when user is active?

查看:47
本文介绍了当用户处于活动状态时如何继续延长会话寿命?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个站点/系统具有登录的会员区,用户很少,但在使用站点/系统时注销非常不方便.

Let's say there's a site/system with a logged in member area, and users are rarely, but very inconveniently logged out while working with the site/system.

由于用户没有闲置很长时间,因此会话可能会过期.即使它们处于空闲状态,我也会添加一个定期的 AJAX 请求,即所谓的心跳,它会更新会话的访问时间和修改时间.我什至在每次用户点击某物或调用心跳时添加一个 touch($session_file) .我也尝试重新生成会话 ID.没有任何帮助.

It's doubtfully session expiring, since the user was not idle for very long. And even if they were idle, I added a periodic AJAX request, a so called heartbeat, which updates the sessions' access time, and modified time. I even added a touch($session_file) every time a user clicks something or a heartbeat is called. I tried regenerating session ID as well. Nothing helped.

不幸的是,到目前为止,我无法在本地重现该问题,因为当有更多请求时,它经常发生.一些 php.ini 参数:

And unfortunately, so far, I was not able to reproduce the problem locally, because it happens every so often, when there's more requests. Some php.ini parameters:

session.use_cookies = 1
session.use_only_cookies = 1
session.cookie_lifetime = 0
session.gc_probability = 1
session.gc_divisor = 1500
session.gc_maxlifetime = 10800

推荐答案

所有提供的答案都显示出对问题的深刻见解,但我只需要分享我的确切问题的解决方案.我终于能够重现问题并修复它.

All the provided answers have shown good insight to the question, but I just have to share the solution to my exact problem. I was finally able to reproduce the problem and fix it.

所以系统包含两个子系统,比如说管理界面和客户端界面.管理员在另一个选项卡中以客户端身份登录时意外注销,并在以管理员身份登录时注销客户端界面.这样做是因为所有内容都写入了一个带有命名空间的会话中.我所做的是删除在注销操作时不断破坏会话的代码,并将其替换为会话命名空间取消设置,并替换为该命名空间的访客会话,该命名空间只能访问登录页面.

So the system contained two subsystems, let's say admin and client interfaces. The admin was unexpectedly logged out when they logged in as client in another tab and logged out the client interface while being logged in as admin. It was doing this because everything was written to one session with namespaces. What I did is remove the code that kept destroying the session on logout action, and replaced it with session namespace unsetting and replacing with guest session for that namespace that only has access to the login page.

这篇关于当用户处于活动状态时如何继续延长会话寿命?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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