php 如何计算网站上的在线用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2843989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to count online users on a website
提问by botmsh
Possible Duplicates:
script to tell me who, and how many users, are online
Best way to keep track of current online users
How should I count the people online on a PHP website at a given time, if they don't have to be logged-in?
如果他们不必登录,我应该如何计算给定时间在 PHP 网站上在线的人数?
回答by Justin Ethier
Use a cookie to identify unique users, and then just keep track of the last time accessed a PHP page. Then come up with a timeout mechanism - for example, if they have not accessed a page in 15 minutes then they are removed from the count.
使用 cookie 来识别唯一用户,然后跟踪上次访问 PHP 页面的时间。然后想出一个超时机制——例如,如果他们在 15 分钟内没有访问过一个页面,那么他们就会从计数中删除。
回答by ZZ Coder
Treat them as anonymous user. Assign a random user ID in a cookie. In your UI, show all the anonymous users as "Guest".
将他们视为匿名用户。在 cookie 中分配一个随机用户 ID。在您的 UI 中,将所有匿名用户显示为“访客”。
回答by Your Common Sense
Just write an IP addresses along with timestamp into a file. On a page load read this file, delete all records, say, 3 minutes older, add current IP and count the lines, write the file back. A lock on this file would be nice.
只需将 IP 地址和时间戳写入文件即可。在页面加载时读取此文件,删除所有记录,例如 3 分钟前的记录,添加当前 IP 并计算行数,然后将文件写回。锁定此文件会很好。
That's all. All other methods listed here are just overpowered for such a trifling thing, inaccurate by design, no matter the method you use.
就这样。无论您使用哪种方法,此处列出的所有其他方法都无法解决这种琐碎的事情,设计上不准确。
回答by Thalaivar
http://www.devarticles.com/c/a/PHP/The-Quickest-Way-To-Count-Users-Online-With-PHP/1/
http://www.devarticles.com/c/a/PHP/The-Quickest-Way-To-Count-Users-Online-With-PHP/1/
I would say to google, you can a lot of scripts and articles related to your query.
我想对谷歌说,你可以找到很多与你的查询相关的脚本和文章。

