Skip to content

Instantly share code, notes, and snippets.

@johnss
Created December 16, 2017 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnss/27702ffc749d9fa2accdace862609259 to your computer and use it in GitHub Desktop.
Save johnss/27702ffc749d9fa2accdace862609259 to your computer and use it in GitHub Desktop.
Online counter using session_save_path()
<?php
define("MAX_IDLE_TIME", 3);
class online{
function who(){
$path = session_save_path();
if (trim($path)=="") {
return FALSE;
}
$d = dir( $path); $i = 0;
while (false !== ($entry = $d->read())) {
if ($entry!="." and $entry!="..") {
if (time()- filemtime($path."/$entry") < MAX_IDLE_TIME * 60) {
$i++;
}
}
}
$d->close();
return $i;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment