Call script on closing a window
Posted 29 March 2006 - 01:46 PM
i want to run a php script after the window is closed.
how do i do that?
basically, i need to call the script for logout when the user clicks the window close (X) button.
Posted 29 March 2006 - 02:17 PM
I wanted to do this a long time ago to create my online stats for an old site but i ended up using datetime in a database and basing it on an action in past 5 minutes as it being an online user then each page they click it updated the datetime of visit..
If you are wanting to log a user out then you could always log a cookie with the session ID in and then on each page look to see if the user has the same session if not then they have oviusly exited all the pages on your site and tryed accessing it again..
Maby a litle more info on exacly what you are trying to acheive
Posted 29 March 2006 - 03:16 PM
Posted 30 March 2006 - 05:27 AM
i'll try to implement shocker's datetime logic probably.
Posted 30 March 2006 - 05:32 AM
Yes, it can...
Posted 30 March 2006 - 05:55 AM
But the prob here is that, after i close the window, i.e., when onUnload is called, i have to run a script for LOGOUT which works fine on closing the window.
But, this also works when i REFRESH the page. So whenever the user refreshes the page, he gets logged out and relogged in automatically. lol.
i guess onUnload isnt appropriate. But is there any logic wherein in can prevent the user from refreshing a page??
Posted 30 March 2006 - 02:05 PM
No, you cannot stop a user from refreshing the page through the browser. And AFAIK, closing the actual browser window does not fire the onUnload() function. Leaving the page will, however, but that doesn't fix your problem.
It does get fired when the user closes the window, I've had to use it in my scripts before. I did forget about the refershing though.
I say go with shocker's idea, the time frame would be best.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users