简体   繁体   中英

Getting Online Users using Session Files

I am trying to find out the number of users online for my site by calculation the total session files created so as to decrease database acess. Can you please throw some light as to how can i do that? And is it possible to access the data stored in those files(for eg User ID) so as to find Who's Online.

Count the number of session files on the server:

$dh = opendir(session_save_path());
$users = 0;
while (($file = readdir($dh)) !== false) {
    if (($file != '.') && ($file != '..')) {
        $users++;
    }
}
closedir($dh);
$online = $users;

Do you want the total number of users who are on your website or do you want the TOTAL number of the users who have visisted id?

The number of your session files isn't equal to the number of the current users. The session doesn't end when user leaves your web site.

A database solution should be better; Also think about a Google Analytics Solution. Google Analytics track the navigation of the users on your website.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM