-
Display online users
this code shows the top 5 users
how do i get it to show the users that are currently online?
PHP Code:
<?php
$connect = mysql_connect("","","") or die("Couldn't connect!");
mysql_select_db("prkscouk_users") or die("Couldn't find database");
$query = mysql_query("SELECT * FROM users ORDER BY id DESC LIMIT 5");
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query))
{
$id = $row['id'];
$username = $row['username'];
$email = $row['email'];
echo "<a href=mailto:$email>$username</a><br>";
}
}
else
{
echo "No users were found.";
}
?>
-
Re: Display online users
First, define "online".
In other words, if I visit a page on your site, when do I stop being online? On this site, for example, it's about ten minutes after the last visit.
To make this work, you need to store the last visit time against each user. When (an authenticated) user visits any page, update this field to the current time. To show all "online" users, select from the users table where the last visit time is less than your predetermined amount of time before the current time.