hi
I am creating a script that counts the users that are logged in. I have found a tutorial of how to make it. It counts the sessions created by reading the session files that are in the session save path. I found out in phpinfo that the session save path = /tmp.
The script isn't working. When i remove the time safety it gives me a result but that is absolutly not correct. Can someone help me with this ?
Your help will be greatly apriciated.
My script :
PHP Code:
<?php
session_start();
session_save_path("/tmp");
define("MAX_IDLE_TIME", 3);
function getOnlineUsers(){
if ( $directory_handle = opendir( session_save_path() ) ) {
$count = 0;
while ( false !== ( $file = readdir( $directory_handle ) ) ) {
if($file != '.' && $file != '..'){
if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60) {
$count++;
}
}
}
closedir($directory_handle);
return $count;
} else {
return false;
}
}
echo 'Number of online users: ' . getOnlineUsers() . '<br />';
?>