To your members table. Add these feilds
time (int)
status (text) or (int)
I wont give you a script as you should search the forums. Ive done at least two of them. Maybe more.
To start id make a function that sees if a cookie or if your using sessions. To see if it exists use isset for that.
Now if your using sessions there is a way to do it with sessions. just read up on it.
Now from there id make sure that the username stored in the session or cookie should be checked with the members table to make sure the username actually exists.
If it does then you can change the status to online if text or if your using int id suggest using 1. A simple Update would do fine there
Before you update though id use time();
So we can then check if the user is offline
From there we update it all..
Ok now to check if there offline
We'd do this.
Use a mysql update
and do this
$timeout = time()-300;
mysql_query("UPDATE table SET status='0'(or offline if text) WHERE time < $timeout");
Hope that helps