We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

how to automatically logout when close the browser in php?

vn4phuong
vn4phuong asked
on
Medium Priority
4,576 Views
Last Modified: 2012-06-21
Hi,
I would like my user to automatically logout when he's closing his browser.  How can I do that.


thanks
Comment
Watch Question

Commented:
User will auto logout when he closes his browser. Session will be lost.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
i am using cookies

Commented:
Cookies will also be expired.
By default, it will kill itself when browser is closed unless you specify it to specify at a specified number of days later.


hongjun
jessegivyDeveloper
CERTIFIED EXPERT

Commented:
Why cookies?  My temporary internet files folder is already cluttered with all those little images you force me to download.

~Happy User

...sorry, just looking for interesting conversation.  Seems like the honorable hongjun has this one under control.  As an option you can manually kill the session, but as was stated above, it's really not an issue, I have however heard that when many of the larger banks delete financial records from the disk, they write the physical addresses to binary zeros seven times, what's the point of that?  Anyway, in jsp, I'm fairly sure it's:

session.destroy()

...but, unfortunatly, my memory isn't what it used to be so there may be other scenarios to consider, here's a link that says you should unregester your variables before doing so, uh I dunno if that's actually necessary
http://www.webdeveloper.com/forum/showthread.php?t=15675

Cheers,

JI

Author

Commented:
function do_whatever()
{

       delete_cookie ( "viet1800" );




 


}
function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}



</script>
</head>
<body onUnload="do_whatever()">

</body>
</html>

how come this code doesn't delete the cookies?

Thanks
you need to set the cookie time to -1 -- which means cookie is deleted when the browser window is closed!
secondly, have an onunload handler on your document as suggested above which calls the function that you want to expire the session.

Commented:
The Unload event only fires immediately before an object is unloaded. Objects are not unloaded when you close your browser window. The BODY Unload event would fire when you browse off to another page.

I suggest you do what is being suggested by 'liviutudor' and set the cookie to expire when the browser session is over (when all browser windows are closed).
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.