简体   繁体   English

如何在关闭浏览器选项卡时清除会话?

[英]How to clear session on closing the browser tab?

Hi I'm trying to clear all the session variables when the user closes the tab, I have tried the following嗨,我正在尝试在用户关闭选项卡时清除所有会话变量,我尝试了以下操作

session_set_cookie_params(0);
session_start();

but it clears the session only when the user closer the entire browser, I have tried searching frome some links but I have found that not working.但只有当用户关闭整个浏览器时它才会清除会话,我尝试从一些链接中搜索,但我发现它不起作用。

Browsers only destroy session cookies when the entire browser process is exited.浏览器只有在整个浏览器进程退出时才会销毁会话 cookie。 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.您可以附加一个onbeforeunload处理程序,并希望设法对服务器进行 ajax 调用以说明选项卡已关闭,但这并不可靠。

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.如果他们关闭一个选项卡,即使用户完全打算继续使用您的站点,另一个选项卡也会被有效地注销。

by : Marc b作者:马克 b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM