Users Online

By EBP on May 18, 2005

echo $usercount; - displays users.

The following code must go at the very top of your page before any HTML is sent to the browser. To call the function and assign the value to a variable, you simple use this line:

$usercount = getUsersOnline();

 <?php
session_start();

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;
}
?>

Comments

Sign in to comment.
Hawkee   -  May 20, 2005

What kind of time frame will this work for? Seems the count will keep counting all the dead sessions that are no longer active.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.