View Single Post
  #1  
Old 03-19-2004, 06:42 AM
 
shirtshop shirtshop is offline
 

Senior Member
  
Join Date: Nov 2002
Posts: 127
 

Default current users online

I want to add a php script to see how many users are online.
This will be nice when it's showing under the subscribe button from the newsletter.
I'm a newby and hope that someone can help me.
This is the script that i found. Maybe there's a better one.
<?

session_start();

/**
* Calculate the number of users online by
* counting the number of session files. Returns the
* number of users on success, or -1 on failure.
*/
function getUsersOnline() {
$count = 0;

$handle = opendir(session_save_path());
if ($handle == false) return -1;

while (($file = readdir($handle)) != false) {
if (ereg("^sess", $file)) $count++;
}
closedir($handle);

return $count;
}

echo "users online = " . getUsersOnline() . "
";

?>
Reply With Quote