I have also worked on something. Similar but different approach yours might be better.
Code:
function do_viewallside() {
global $db, $user, $the_template,$current_user,$main_smarty;
$online2 = 1;
$idle2 = 2;
$onlineLimit2 = time() - $online2*60;
$idleLimit2 = time() - $idle2*60;
$sql = "SELECT user_login, user_modification, user_lastactivity, user_logged_in FROM " . table_users . " WHERE user_logged_in = 1";
$list_users = $db->get_results($sql);
echo "<table border=\"0\" style=\"margin-bottom:25px\">";
echo "<tr><th colspan=\"3\" style=\"text-align=center\">Who is Online</th></tr>";
if($list_users) {
foreach($list_users as $row) {
$lastactivity = strtotime($row->user_modification);
if ($idleLimit2 < $lastactivity) {
if($onlineLimit2 < $lastactivity) {
echo "<tr>";
echo "<td><a href=\"".my_base_url."/user.php?login=$row->user_login&view=profile\">$row->user_login</a></td>";
echo '<td><img src='.my_pligg_base.'/templates/'.$the_template.'/images/friends_online.ico alt="online" style="margin-left:4px"></td>';
echo '</tr>';
} else {
}
}
}
}
echo "<table>";
}
The code detect who is online and who is offline properly
But the IF statement highlighted don't work well for some reason. So it doesn't detect if user has no activity for some time. Meaning that if he doesn't logout himself it will detect him as Online, I think maybe it hasn't taken effect yet, but I set the value low, so I think it should have.
ANy Help thanks.
This was taken from the Friend module by AnAlien
http://forums.pligg.com/pligg-tutori...-activity.html