开发者

How to count online users on a website [duplicate]

开发者 https://www.devze.com 2022-12-30 05:28 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicates: script to tell me who, and how many users, are online
This question already has answers here: Closed 12 years ago.

Possible Duplicates:

script to tell me who, and how many users, are online

Best way to keep track o开发者_开发问答f 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?


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.


Treat them as anonymous user. Assign a random user ID in a cookie. In your UI, show all the anonymous users as "Guest".


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.


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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消