有没有注销用户时关闭浏览器的可靠途径? [英] Is there a reliable way to log a user out when the browser is closed?

查看:89
本文介绍了有没有注销用户时关闭浏览器的可靠途径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找到注销用户或在浏览器关闭时放弃自己的会话的可靠方法。有没有办法用标签浏览器做到这一点?任何建议都AP preciated。谢谢!

I am looking for a reliable way to log out a user or abandon their session when the browser is closed. Is there a way to do this with tabbed browsers?? Any suggestions are appreciated. Thanks!

推荐答案

有没有可靠的方法来做到这一点的立即的当客户关闭浏览器。当此事件过程中触发一个Ajax请求还有的 beforeunload 事件,但即使是这样,它不能保证永远到达服务器。尽管如此然后,在你一个问题,多个浏览器标签。

There is no reliable way to do this immediately when the client closes the browser. There's the beforeunload event, but even then, when you fire an ajax request during this event, it's not guaranteed to ever reach the server. Still then, you've a problem with multiple browser tabs.

最可靠的方法是在服务器端(例如1分钟)相对较短的会话超时,并介绍在客户端(例如每30秒)的ajaxbased心跳保持会话活着。

Most reliable way is to have a relatively short session timeout in the server side (e.g. 1 minute) and introduce an ajaxbased heartbeat on the client side (e.g. every 30 seconds) to keep the session alive.

有可能会根据为您所想,这是解决方案的唯一功能要求更好的方法。例如,如果你的实际的意图在于限制所有的登录到1元注册用户,那么你最好收集所有的登录和相关的会议,然后比较这对每个登录和无效,如果前面的会议任何present。这样,它会用JS在客户端上工作,以及禁用。

There may be better ways depending on the sole functional requirement for which you thought that this is the solution. For example, if your actual intent is to restrict all logins to 1 per registered user, then you'd better collect all logins and the associated sessions and then compare this on each login and invalidate the earlier session if any present. This way it'll work as well on clients with JS disabled.

这篇关于有没有注销用户时关闭浏览器的可靠途径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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