简体   繁体   English

使用会话文件获取在线用户

[英]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. 并且可以访问存储在这些文件中的数据(例如,用户ID),以查找谁在线。

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? 您是否想要网站上的用户总数,或者您想要访问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(分析)解决方案。 Google Analytics track the navigation of the users on your website. Google Analytics(分析)跟踪您网站上用户的导航。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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