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 ....????
Dedstroying session , on closing the browser window
Moderator: General Moderators
Re: Dedstroying session , on closing the browser window
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').
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
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
In theory (and perhaps some practical sitations) it will work. But there are plenty of scenarios where it certainly won't.