Friend online/offline

Hello

I currently have a friend system.

How would I display a online/offline status of the users friend?

I presume I would have to use sessions, but not sure how to do it.

You’d have to store the ‘latest activity’ timestamp for each user, and then you can check if that latest activity has timed out.

Hello, Thank you for your response.
Sorry im a bit noobish, can you be a bit more specific please.

I understand I have to create a latest_activity timestamp session for each user, but I am not sure where to go from here.

No, not a session. A session is for the user itself. To store whatever data you need during a users session.
To know who is “on line” at a given moment, you could add a column to the users table in which you store the timestamp every time the user does something. Of course, when the user logs out, his status will be offline. But if the user closes his browser without logging out, the status would remain online. To prevent showing these users as online all the time, you check their last activity timestamp. If it’s more than let’s say 10 minutes since their last activity, you consider them offline.

Ahhh, understood. Thank you.