I am working on a quite simple custom made content management system (CMS). There is a database table containing usernames, passwords, emailaddresses and a date/time field showing when the user logged in for the last time (I used “NOW()” in the query when updating).
When an user successfully logs in, the script will update a table in the database and sets the new time (using NOW()).
Now I would like to show which users are currently logged in, in the past 5 or 10 minutes. I have no idea how to accomplish this, therefore I am calling for your help. On the internet I read I need to do this with a timestamp, but I have no idea how this works.
-
I need to know how to set a specific timestamp.
-
I need to know how I can check in PHP if the user has been logged in in the past 5 or 10 minutes so I can display their names somewhere.
Thanks for your help!
1.
Why do you need to set a custom timestamp? Using NOW() is all you need.
2. This query will find all users where the column
latest_loginis in the past 10 minutes:SELECT * FROM users WHERE latest_login >= DATE_SUB(NOW(), INTERVAL 10 MINUTE)