Jump to content

Logout when browser is closed


Recommended Posts

Setting cookie expiry is relatively straight forward. I don't really know where the cookie is defined, but chances are somewhere in the file tree there is a class file or plain included file called cookie.php

Here is the information from the php manual about setting a cookie to expire on browser close:
http://us.php.net/setcookie

Basically what you have to do is set the cookie expiry to 0 which will disable it once the browser is closed.

Link to comment
Share on other sites

I dont know prestashop good enough but like i said, chances are there is a file named COOKIE.php so do a search for that file name and see what pops up. Once you get in there you will be able to find that excerpt of code easily.

Usually the cookie info is in it's own page and just included in something like application_top which you will NOT find the variable

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

I'm able to clear cookies when the browser is closed, but it won't always works.

Basically, I use a javascript function to detect if the user close his browser and, if positive, I make an ajax call to the index page, passing the logout parameter (it's the same path used by logout link/button).

 

function fnUnloadHandler() {
 xmlhttp=null;
 if (window.XMLHttpRequest)
 {// code for Firefox, Opera, IE7, etc.
	xmlhttp=new XMLHttpRequest();
 }
 else if (window.ActiveXObject)
 {// code for IE6, IE5
	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
 }
 if (xmlhttp!=null)
 {
	xmlhttp.open("GET","http://www.yourprestashopsite.com/index.php?logout",true);
	xmlhttp.send(null);
 }
 else
 {
	alert("Your browser does not support XMLHTTP.");
 }
}

 

problems with this approach:

- Javascript must be turned on (minor problem nowadays)

- since it should works when you close the browser, it won't work when you close only the browser's tab

 

note: I've added some code in the cookie logout function (classes/Cookie.php) in order to launch sql commands when the function is called. It works even when the tab is closed, while cookies aren't deleted.

Link to comment
Share on other sites

  • 2 years later...
×
×
  • Create New...