It is very easy:
Just have a table in a Mysql database with two fields: username and logtime
everytime a user uses your website; you use a function which I will call logonline;
in this function you will do 2 things: you delete old usernames from the table and you add the new one.
With old usernames I mean: with a logtime of time()-800 or something.
and you record a new row with username and time().
You will have something like this:
$logtime = time();
$request = mysql_query ("DELETE FROM online WHERE (logtime < ".($logTime - 900)." or username='$username')");
$sql = "INSERT INTO online VALUES ('$username',$logtime)";
if (!$result = mysql_query($sql)){echo mysql_error();}
I think you can figure out how to recall the online users now... 🙂
Good luck.