User status: online or offline

Can you please tell me how to correctly implement the user status [on] / [off]? I wrote a small script, but it constantly brings the user online.


Answer 1, authority 100%

Let’s take the example of Vkontakte.ru, a person is kept online for about 15 minutes after he left online.

The following algorithmis obtained:

1) Whenever accessing the server, lastvisit (timestamp) is placed in the table where the given user is located.

2) To check online or not, pull out its value and compare when the last visit was (for example, if more than 15 minutes, i.e. subtract 15 minutes from time() (timestamp ) and check lastvisit is greater or less than the resulting date).

3) To display the list online, do the same calculation, only pull from the database after subtracting 15 minutes of all those who fit these parameters.


Answer 2, authority 50%

The theme is as old as the world. All this is implemented using sessions!
Here is herean example.

Leave a reply

Please enter your comment!
Please enter your name here