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

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

问题描述

我有用户登录/注销应用程序: 我想销毁会话,当我关闭浏览器((所有选项卡)),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天全站免登陆