强迫用户离开我的php网站时注销? [英] Force users to logout when they leave my php website?

查看:72
本文介绍了强迫用户离开我的php网站时注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的php应用程序中,我正在使用$ _SESSION跟踪用户是否已登录.如果用户在我的网站上的 http://someotherwebsite.com ,我希望自动注销它们,以便如果它们返回 http://mysite.com 上的任何页面,则需要重新登录.

有一种简单的方法吗?

解决方案

您不能明确告诉用户何时离开您的站点,最好的选择是在会话中实施超时. /p>

正如大多数答案所说,您可以检查JavaScript事件 BalusC指出,使用不支持它的Web浏览器,例如Opera.

因此,我坚信在会话上实施超时是强制注销的最佳方法.

In my php application, I'm using $_SESSION to track whether a user is logged in. If a user leaves any page on my site at http://mysite.com and goes to http://someotherwebsite.com, I want to automatically log them out, such that if they return to any page on http://mysite.com, they need to login again.

Is there an easy way to do this?

解决方案

You cannot explicitly tell when an user leaves your site, your best bet would to be to implement a timeout on your sessions.

As most of the answers have said, you could check with the JavaScript event onbeforeunload but the user can by-pass this by disabling JavaScript or, as BalusC had pointed out, using a web browser that does not support it, such as Opera.

Therefore, I strongly believe implementing a timeout on your sessions is the best way to force a logout.

这篇关于强迫用户离开我的php网站时注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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