It took me quite sometime to figure this one out. This will display who is currently on-line. I'm using this in my personals program I'm currently writing.
$timeoutseconds=300; // Timeout value in seconds
$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
mysql_connect($server, $db_user, $db_pass) or die ("Useronline Database CONNECT Error");
mysql_db_query($db_name, "INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF','$username','$id')") or die("Useronline Database INSERT Error");
mysql_db_query($db_name, "DELETE FROM useronline WHERE timestamp<$timeout") or die("Useronline Database DELETE Error");
$result=mysql_db_query($db_name, "SELECT id, username FROM useronline WHERE file='$PHP_SELF'") or die("Useronline Database SELECT Error");
THIS DISPLAYS WHO IS ON-LINE
$on_string =" ";
while ($geton_now = mysql_fetch_array($result))
{
$online_id = $geton_now['id'];
$contact_username2 = $geton_now['username'];
$on_string .="<a href=\"show_contact.php?id=$id\">$contact_username2</a> ";
}
The show_contact.php is what I use in my personals program to show their contact information. Just call $on_string and it will display who they are.
The user_online database has the following:
timestamp int(15) allow null NO Primary
ip varchar(40) allow null NO Indexed
file varchar(100) allow null NO Indexed
username text allow null NO
id text allow null NO
Hope this helps.
Michael