This could be very simple..
Each login creates a session (if you are using sessions i.e. you have session_start() at the top of the page)
You could then just count the amount of active sessions.
PHP:
/* Define how long the maximum amount of time the session can be inactive. */
define("MAX_IDLE_TIME", 3);
function countactiveusers(){
if ( $directory_handle = opendir( session_save_path() ) ) {
$count = 0;
while ( false !== ( $file = readdir( $directory_handle ) ) ) {
if($file != '.' && $file != '..'){
// Comment the 'if(...){' and '}' lines if you get a significant amount of traffic
if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60) {
$count++;
}
}
closedir($directory_handle);
return $count;
} else {
return false;
}
}
echo 'Number of users online: ' . countactiveusers() . '<br />';
Simples!
This method does not rely on using a database which is faster, but gets you no stats