FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Can I detect a page close?

 


DoctorBeaver
I've knocked together a membership system for my site using php/mysql. As part of it I want to keep statistics of which pages visitors access and how long they spend there.

If they use the nav menu or back button it works fine as each time they access a page, I put the logout timestamp on the current record and create a new 1 for the page they go to.

However, if the visitor leaves the site by simply closing the window rather than logging out properly, I'm left with a record that has no logout timestamp. Obviously that will play havoc with my stats. Is there anyway I can get around this?
Nyizsa
Yes, you can do something with Javascript. Try scripting the onunload event of the <body> element!
DoctorBeaver
I was trying to avoid Java, but I suppose it could be the best answer. Thanks
Nyizsa
DoctorBeaver wrote:
I was trying to avoid Java, but I suppose it could be the best answer. Thanks

Yes, you are right - with clients Java turned off it won't work. But since HTTP uses transactions instead of connections, the only way to know about closing of a session is detecting client-side events.
An other possible solution might be setting up a timeout. If somebody didn't request a page from you in the last 10 (or as many as you want) minutes, you can consider that session closed, and run the logout script.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.