谁的在线脚本问题

Whilst creating a Who's Online script for my website, I've noticed that users of the same computer could of course have a different browser preference to other users.

What should happen in this situation?

I wish to find out the total number of users currently online, along with a breakdown of how many of these users are members or guests, and I need to find out how many users where online today, along with a breakdown of how many of these users are members or guests.

Any help is greatly appreciated.

You can accomplish this using a sql database. Different browser settings do not make any difference, except for proxy.

Every time someone opens your website, get their IP address and insert it into a table with this structure:

(varchar)ip, (int)time

Check if the ip is already in the database first and if that's the case, just update the time with current time.

time();

to get the number of online users just select from table where current time - time <= 300(online - has visited the site in the last 5 minutes). To check if it's a user, just check if the ip matches any accounts' ip address. If you don't store your members' ip addresses then it's about time to. Just update their ip address every time they login.

To get the number of people who visited your website today select from that table where current time - time <= 86400 (24 hours)

If you want the 'online today' counter to reset at midnight, create another column in the table storing the date(without time) the user visited the website, then simply check if it's today's date or delete all records every day.

Use session in PHP PHP SESSIONS , and write your session data to your databse, for example create a session with the key guest for guests and members for users who are logged in.

Then write your session data to your database and make a unique session key too to prevent duplicate entries in your databse.

However if you use your mind a little bit more then you will also be able to stop duplicate entries of the same user from different browsers.

Also write their IP's to your database.