Thanks for the advice

Here's where i'm up to now...I have put the following code into the page that displays the user status:
<body onunload=<?php require_once("reset_login.php");?>>
...and this is the reset_login.php file:
<?php
include("connect.php");
mysql_query("UPDATE users SET status='Offline' where alias='".($_SESSION['alias'])."';");
?>
As soon as the page loads, the user status is updated to offline, as if it is executing the query when the body loads instead of unload.
I have also tried putting the php in a JavaScript function in the page header then calling it on body onunload but it does the same again, executes the query on body load.
Thanks also s.dot I have tried onbeforeunload but still does the same.
If you have an idea where i am going wrong, PLEASE HELP!! I am pulling my hair out!
