Paul
Paul

Reputation: 11746

How do I get a list of active users with PHP?

I currently maintain a DB table of users, when after logging in I update the table with their ID and login_time. This works to a point but currently I can't tell if the user has been active since the login or for how long.

Is there a better way to get a complete list of users that have been active in the past X minutes?

Upvotes: 2

Views: 1910

Answers (2)

Magnus
Magnus

Reputation: 980

You'll have to keep track of when the user made their last request in your database as a separate table or column. You can then formulate a query to select, e.g. all users that have made a request in the last 5 minutes.

PHP itself does not store - or care for - that kind of information. Unless you happen to have your own session management module which does store this kind of information, then you could use data from that.

Upvotes: 2

G-Nugget
G-Nugget

Reputation: 8836

The best way to get what you need would be a "Last Activity" column in the users table. You would just update it whenever a user access a page. Depending on what information you need it could replace the login_time column or it could be a new column.

Upvotes: 3

Related Questions