首页 > 解决方案 > How count online users without using database?

问题描述

here is the code which I'm using to count online users but this is not working properly this count just 1 user every time. If that user is offline then this shows 0 users online. Please help why not this code working properly.

defined('MAX_IDLE_TIME') or define('MAX_IDLE_TIME', 10); 
class online {
    public static 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 * 10) {
                    $i++;
                }
            }
        }
        $d->close();
        return $i;
    }
    
}

标签: php

解决方案


推荐阅读