Can anyone cite examples for a user's status? (online & offline)


So I was thinking about getting the user table where status = online / strong>, but I know that when the user shuts down the computer without clicking Log out, the table will not be changed offline , so I want to know what is best:



What do you recommend me? I want to make data with "Last Activity" where if it does any action involving $ _GET or $ _ POST updates the status table (I will convert to TIMESTAMP or DATETIME) X minutes ago or something, I want examples so I will not put my DATABASE in question here. Thanks for all the reviews, and examples discussed.

I still do not understand how Gmail-type services, Facebook among others make this relationship between offline and online, so if anyone is also willing to explain this, welcome

asked by anonymous 13.05.2015 / 01:23

3 answers


Use TIMESTAMP I think it will be easier for you to interact on your system without errors. Gmail seems to do this verification with the user mouse , because when you are in chat it is normal, "online", but when you go to another tab and passes a x minutes away from the chat tab so it considers you as "idle". After you move the mouse over some element of the site then it should send a command to the server saying "Look, Kevin is still available, so let's change his status to online."

13.05.2015 / 01:28

Look at the answer is very simple. There is no click checking or something similar on the page. The simplest way is to check the time the user accesses the system and make a comparison of 1 minute or less with the current time if it is off for more than 1 minute for example it appears offline. For this to work, you create a routine that updates the user's timetable while he or she is online on the page in this way if it is left out for more than 1 minute when other users check it will appear offline through that time comparison.

31.05.2015 / 07:24

Good evening, Kevin, I already did this on one of my first projects (a social network mobile) when I was 16 years old. The answer is very simple, every time logged in user does some interaction with the site (changing or updating the page itself) you call a function or method responsible for going in the bank and update some field of some table with exact date of the interaction. In your script before calling this function you run a second function that checks whether in the table that holds the last accesses of each user if the current time is X minutes greater than the last one saved in the table if positive the user, if negative updates the table using the first function quoted above.

When it comes to showing other users who is online, you only have to SELECT the database by listing all the users who have the last access saved up to the X minutes allowed .

Tip: To make it more scalable, you can create a third function that will restrict these queries / writes to the database, caching the last access of each user so that they do not require too much from the database. This is only if you have good traffic on your site, otherwise you can use only the simple solution that I pointed out.

I hope to have helped, hug.

31.05.2015 / 07:55