Detecting if a user has left the site

Associate
Joined
21 May 2003
Posts
1,365
I have a reservation system that currently reserves tickets for 5 minutes, after which they get released. Unfortunately this is still causing problems as users may browse away from the site or close their browser window leaving those reservations locked until the time-out. I could reduce the time-out but this would be a problem for users who are still completing a form or whatever on the site.

Basically I'm asking if there is a reliable way to detect if a user has left the site, either by browsing to another domain or closing their browser window?

I was thinking of calling the ticket release function with an ajax call from the browsers onunload event, but that would mean that it would be called even if they were just browsing between pages on my site.

Is there a way of getting the next url to be loaded from within the onunload call? I guess adding an ajax call for every page unload is going to be an additional strain on the server... probably a bad idea all-round.
 
platform = PHP/MYSQL

Ideally i'd be able to test client side for a change in domain and then fire off the ajax request as the last thing the browser does before it moves to the new site.

It doesn't have to be 100% reliable because the reservations are released after a timeout by default, but the quicker they are released the better.

The browser wouldn't have to wait for a response because there's nothing to send back to it, it's purely a server-side action.
 
Jaffa_Cake said:
Or you could do a ajax loop every 2 minutes. Not exactly resource heavy.

I just love ajax :D

Maybe not on a low-usage site but if you're serving 10k+ visitors an hour during peak times then it's a different kettle of fish.

I guess I'll just have to reduce the timeout on the reservations to 3 minutes.
 
Back
Top Bottom