Jump to content

logout on closing browser


golem

Recommended Posts

Hi,

How can I run a logout script when a user close the browser.

 

This is for a login/registratin system, to change a flag in teh database from "online" to "offline" if user closes the browser without loging out.

 

Thank you.

:o

Link to comment
Share on other sites

possibly javascript.  php is server side, and has no idea what is happening on the user's end unless it is sent something.  i don't do javascript though, so someone else is going to have to chime in.

 

the only way to do it purely in php would be to save a timestamp when someone logs in, and if their session has been inactive for X number of minutes then flag them as logged out.  this script would likely be set up to run every X minutes with cron, and will likely hit your database more times than it is worth.  it won't have anything to do with the window closing though.  if you're interested in this method, a helpful tutorial can be found over at codewalkers.com:

 

http://codewalkers.com/tutorials/14/1.html

Link to comment
Share on other sites

Thanks for your answer.

 

If I understand right, if I have a database of 50000 users, I will have to go through all of them periodicaly and compare current time with timestamp stored in the database from last activity? .

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.