Search code examples
phpmysqltimestampconnectionmembership

How to implement a "who's online" feature in PHP?


How would one go about implementing a "who's online" feature using PHP? Of course, it would involve using timestamps, and, after looking at phpBB's session table, might involve storing latest visits in a database.

Is this an efficient method, or are there better ways of implementing this idea?

Edit: I made this community wiki accidentally, because I was still new to Stack Overflow at the time.


Solution

  • Using a database to keep track of everyone who's logged in is pretty much the only way to do this.

    What I would do is, insert a row with the user info and a timestamp into the table or when someone logs in, and update the timestamp every time there is activity with that user. And I would assume that all users who have had activity in the past 5 minutes are currently online.