Page 1 of 1

Dedstroying session , on closing the browser window

Posted: Wed Jul 14, 2010 2:29 am
by napster
hey guyz , i m in a big hell while creating a chat server , me getting a problem that when ever a user logout , the session successfully destroys , but on closing the browser window without logging out , marks the user as available in other's account ...
Can anyone help me how to distroy a session , by closing the browser window , without clicking on log out ....????



Re: Dedstroying session , on closing the browser window

Posted: Wed Jul 14, 2010 5:17 am
by Apollo
You can't force a browser to send a logout notification before it closes (or even when it closes the page).

What you could do it is keep sending "I'm still online" notifications in the background using javascript / Ajax. If you are not receiving any updates anymore, you know the user is offline (or his browser crashed, or his internet was disconnected, or he's moving to a different WiFi spot, or he put his laptop to sleep/hibernate, or whatever - probably all valid reasons to consider him 'gone').

Re: Dedstroying session , on closing the browser window

Posted: Wed Jul 14, 2010 10:12 am
by buckit
you could try using the onunload event. so when the browser is closed it opens a popup window that runs your logout script and closes the popup. in theory that should work. have never tried it.

Re: Dedstroying session , on closing the browser window

Posted: Wed Jul 14, 2010 10:31 am
by Apollo
In theory (and perhaps some practical sitations) it will work. But there are plenty of scenarios where it certainly won't.