R
R
Ruslan2015-12-06 11:12:42
PHP
Ruslan, 2015-12-06 11:12:42

How to determine if a user is online?

Share your experience who did this:
You need to determine who is online on the site and who is no longer (if he did not show activity on the site for 15 minutes, he is offline), now the status of online or offline will affect some of the site's behavior.
In the future there will be a general chat, private chat, and more.
The project on Yii2 is interested in various options for the approach, most likely there are a lot of answers on the Internet, but new solutions may appear.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2015-12-06
@Stalker_RED

With each hit, we record the date and time.
Compare it with the current time.
??????
Profit!

I
IceJOKER, 2015-12-06
@IceJOKER

On each page (preferably in one file that is connected to each page), save the current time for the current user, for example - last_active = NOW()
well, the user is considered online if last_active + 15 минут > NOW()(see for yourself in what format to store the date / time)

now the online or offline status will affect some site behavior.
In the future there will be a general chat, private chat, and more.
- well, who cares?

V
Viktor, 2015-12-08
@Levhav

If you're going to do chat then you'll probably need a comet server. For example , here is an article with an example of how to determine whether a user is online or not using a comet server. Moreover, in this case, the definition will be accurate with an error of less than 1 second, and not in the style that once was 14 minutes ago, and now it is still online.
I wrote a chat not long ago and there I also used the definition of whether a person is online or not. Maybe you need my private chat

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question