Sboniso Marcus Nzimande Sboniso Marcus Nzimande - 18 days ago 7
Ajax Question

I need to show which users are online for my AJAX Chat

I have an inline chat application which I got from Ajax Chat, which is working brilliantly. The application allows a user to chat with users that are registered on the system. Ie: Here is a list of the users

Now I need to show if the user is online or offline.

So my question is how do I show online users using PHP?

Thank You

Answer

Basically what you need is a way to register users activity.

One way you can do this is doing it by sessions within PHP, and you log these. There are tons of ways to register then your activity in a log. If the activity is not updated for example in 5 minutes, the user is offline. Bassically you just need then a sessionId, and a timestamp (and i would recommend this also to hang to a userid). If offline, there is no userId assigned and when online you add a userId. If you have those, its pretty easy. Its a matter of updating them constantly when a new page is loaded and if they log out, you simply destroy the session, or update it so it wont be linked to the user.

It may not be the best system, but it works, and it might help you.

Comments