0

I'm trying to delete the active login session when user will closing the windows or browser.

ini_set('session.cookie_lifetime',  0);
ini_set('session.use_only_cookies', 0);
ini_set('session.cache_limiter', 0);

this is working but when I'm making the check box on Restore previous session on firefox its getting restore. how could i delete the active session or cookies using JavaScript

         window.sessionStorage.removeItem('log'); 
   $.post(  baseurl+"/logout",
    function(data, status){
        //alert(data);
      window.location.replace(contextPath);
    }); 

I would like to delete the session or cookies once full browser or my application all page is closed

  • 1
    Possible duplicate of [Clear cookies on browser close](https://stackoverflow.com/questions/1783302/clear-cookies-on-browser-close) – Murali Nepalli Jul 25 '19 at 06:36

1 Answers1

0

You need to add event beforeunload then place the mechanism of cookie clearing for it's callback function.

window.addEventListener('beforeunload', function(event) {
    document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });
});
Lawrence Paje
  • 339
  • 3
  • 4