简体   繁体   中英

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. 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.

by : Marc b

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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