Ok.. after a day of going crazy trying to search for help with building a who's online script.. i finally came up with this little solution... BUT.. I'm not sure if it's a good way to keep track of online users... here is the code. I'll explain afterwards.
<?
$oTime = time();
$pastTime = time()-300;
$db = mysql_connect("localhost", "root");
mysql_select_db("test", $db);
mysql_query("UPDATE users SET oTime = '".$oTime."' WHERE username ='".$logged_in_user."'");
mysql_query("UPDATE users SET iTime = 0 WHERE oTime < '".$pastTime."'");
?>
Basically I've added a field to my user table that says "oTime" and what I've done is added the code above to all my php pages.. so that when the user loads the page.. the script sends the current time to the user table.
It also at the same time updates the table to set a user's time to zero if their time hasn't been updated within the past 5 minutes.
When I create my whosonline.php page I just add the following to query the results..
<?
$db = mysql_connect("localhost", "root");
mysql_select_db("test", $db);
$query = "SELECT username FROM users WHERE iTime != 0 ORDER BY RIGHT(username, 2) ASC";
$result = mysql_query($query);
while ($record = mysql_fetch_assoc($result)) {
while (list ($fieldname, $fieldvalue) = each ($record)) {
echo $fieldname.": <b><a href='profile.php?name=".$fieldvalue."'>".$fieldvalue."</a></b><br>";
}
echo "<br>";
}
?>
What do you guys think? if this too much for a server that has a lot of visitors? I'm running a Windows p4 with 1.5gb ram.
If you know of any other ways of doing a better who's online script please let me know... because I'm a total newbie at all of this..:glare: