FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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.
Related topics
How Spyware Works!!!
20 Frih$
Fortran Tutorials(77)
small question if you have spare time
Can you run your own phpBB forum thru FRIHOST?
where do i apply for a hosting
hosting a domain...
is there a way to search your forum for older topics?
directory listing
Change my Subdomain name
Log onto to Control Panel
Detect click on an area in the page.
How to detect and fix a machine infected with DNSChanger
How to Kill Ants?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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