execute code when browser closes?



converge said:
I am designing a site where paying users can login to a searchable scientific database. But I only want them to be able to be logged in on one computer at a time. If a user clicks the logout button, I set a field in my table to LoggedIn = False. But what if they just close the browser? Then the database still thinks they're logged in. Is there a way for sessions to accomplish this task?

You can use session on your site or cookie. You can config session/cookie that them destroy than browser close.
Im not sure if there is a "session_onend" function that is over-ridable. However, while overlooking the PHP documentation, I came across this function session_set_save_handler()... This might help you out.

Let me know if this helps

When a browser is closed it doesn't send any information back to the website (at least not that I'm aware of). In between serving pages the server doesn't know if the browser still exists or not. The session is managed by use of a cookie (the session manages it automatically) which is set to expire immediately, so as long as your browser window doesn't close the cookie value (and therefore session ID) will remain active.

If you wanted to log a user out you could put an Javascript onUnload command in the body tag to open up a new window (Goodbye page, or 'Logging you Out' which would contain the code to log a user out), and this will be executed when a user leaves the page.

Of course you don't want this to happen every time they change a page, so you might want to make some use of frames and put the code within the frameset, so when they leave the site or close the browser it'll activate the code.

I've never actually tried it myself, but in theory it should work. You might have to play around a bit with it first.
One option i can think of is making a popup window that pops up then the main page is accessed or when the user logs in. and if u can start with the window maximised.

This window could have the close button disabled, and at the top and bottom of the page it has a close button, when clicked it logs the user out then closes the window

window.onClose and window.onExit don't work in IE 6 :(
Did you try onUnload in the body tag?

but evertime the user clicks on a link or refreshes the page it will log them out...

unless at the beggining of everypage there is a script that logs them back in automatcly?