This is a bit late, I know, as I only just now came to this forum on a random chance.
My suggestion is to do what Gmail does. Every one minute, save the current time. Then you can tell when the user left the website within 1 min. accuracy. If you need a greater or less accuracy, then just adjust the time interval.
To do this with PHP and Javascript you'll need to use the popular "AJAX" technique.
2 good sources for "AJAX" are.
http://www.phpbuilder.com/columns/kassemi20050606.php3
http://www.pixel2life.com/twodded/t_...to_send_data_/
in quick Pseudo code it would look like thing like this.
PHP timeDBSave.php
Code:
$Timestamp = $_REQUEST['timestamp'];
$query = "INSERT INTO MyTable Timestamp = timestamp";
executeQuery($query);
Code:
Every x seconds
{
Execute_XMLHttpRequest(timeDBSave.php);
}
Sorry, I don't have time to execute the pseudo code for the "AJAX" part, but you can easily check out the examples in the above two links to understand that.
Cheers,
Fozzy