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.
精彩评论