浏览器选项卡关闭时销毁会话 [英] destroy session when broswer tab closed

查看:50
本文介绍了浏览器选项卡关闭时销毁会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用户登录/注销应用程序:我想销毁会话,当我关闭浏览器((所有选项卡))、IE、Firefox 时它工作正常.但是我想在用户关闭单个选项卡时销毁会话.我正在使用:

I have users login/logout application: I want to destroy session, its working fine when I close the browser (( all tabs )) , IE , Firefox working. But I want to destroy the session when user close the single tab . I am using :

session_set_cookie_params(0);
session_start();

推荐答案

浏览器只有在整个浏览器进程退出时才会销毁会话 cookie.没有可靠的方法来确定用户是否/何时关闭了选项卡.您可以附加一个 onbeforeunload 处理程序,并希望设法对服务器进行 ajax 调用以告知选项卡正在关闭,但它不可靠.

Browsers only destroy session cookies when the entire browser process is exited. There is no reliable method to determine if/when a user has closed a tab. There is an onbeforeunload handler you can attach to, and hopefully manage to make an ajax call to the server to say the tab's closing, but it's not reliable.

如果用户在您的网站上打开了两个或多个表怎么办?如果他们关闭一个标签页,即使用户完全打算继续使用您的网站,另一个标签页也会被有效地注销.

And what if the user has two or more tables open on your site? If they close one tab, the other one would effectively be logged out, even though the user fully intended to keep on using your site.

这篇关于浏览器选项卡关闭时销毁会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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