的PHP,如何检测会话ID是死的还是活的? [英] php, how to detect is a session ID is dead or alive?

查看:97
本文介绍了的PHP,如何检测会话ID是死的还是活的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在30分钟后使PHP会话到期?

Possible Duplicate:
How do I expire a PHP session after 30 minutes?

如何检测会话ID是无效还是有效? 假设有人登录-创建了一个新会话,我保存了会话ID.如果他从另一个浏览器登录,我可以确定他已登录两次.但是如何检测他是否注销?

How to detect is a session ID is dead or alive? Lets suppose somebody logged in - a new session is created and I save the session ID. If he logins from another browser, I can determine that he is logged in twice. But how to detect if he logs out?

推荐答案

您需要做的是,当他在新的浏览器上登录到他的帐户时,找到与他的帐户相关联的旧sessionID并使它过期.当他单击注销按钮时,您可以退出该sessionID.

What you would need to do is when he logs in to his account on a new browser, find the old sessionID associated with his account and expire it. When he clicks a logout button, you can then retire that sessionID.

对不起,我读错了你的问题.您想要做的是设置会话超时,因此,如果超时,您将认为会话已死并使会话过期.在每个页面请求上,您都将续订过期以使其生效.如果他们从其他浏览器登录,则可以假定旧浏览器中的会话是旧会话,并立即终止该会话,或者使其超时超时.

Sorry I read your question wrong. What you want to do is set a session timeout so if the timeout is reached, you assume the session is dead and expire it. On each page request, you will renew the expiration so that it is live. If they login from another browser, you can assume the session in the old browser is old, and expire it right off the bat or let it expire with the timeout.

然后,您可以检查页面加载时的会话超时,或者运行将在会话数据库中运行并使所有旧会话到期的cron脚本.

You can then check session timeouts on page load, or run a cron script that will run through the session database and expire all old sessions.

这篇关于的PHP,如何检测会话ID是死的还是活的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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