How to handle online status. Guest, users, etc.

What is the best way to track how many users and guests are online? Im making a forum for fun and learning

Now I have 2 fields in the user table with the name is_onlineand last_access_time.

If the current time is 5 minutes or more than last_access_time, I set is_online to zero. And if the subscribed user updates the browser, I set it to 1.

But what about the guests? I want to keep track of how many guests, too.

Another thing that would be really cool is to show which page the user is viewing. and on the page, for example, forum topics, 5 guests, Homer and Homer are viewing this page. But how do I structure this? Hmm, maybe I should ask one more question.

I do not know what should I do

What are you offering?

+3
source share
3 answers

I would use cookies for this. Set a cookie when a user logs in (check first to make sure that it does not exist). An easy way to generate a unique identifier for this user is to hash your IP plus the current time.

$id = md5($_SERVER['REMOTE_ADDR'] . time());

Save this identifier in your database and use it for reference

, , $_SERVER ['PHP_SELF'], $_SERVER ['REQUEST_URI'] php-. . php.net , _SERVER, , , , , (ex index.php). .

, , , , . cookie cookie .

+1

, , , . , , . .

, IP/HTTP-User-Agent, X .

0

Source: https://habr.com/ru/post/1756999/


All Articles