0

I have a website that has members log in. I store the members/users in a users table in a MySQL database. How can i on my website show a table with all the users currently logged in. The way i wanted to do it is have an extra table in the database that would store the currently logged in users but i am not allowed to do that. Does anyone know how to achieve this? Any help or links would be much appreciated. Thanking you in advance.

Liam Domingo
  • 263
  • 2
  • 6
  • 18
  • I was told i am not allowed to change the database, cause that is what i first thought of doing, so i cannot add a column called lastactivitydate to the users table. – Liam Domingo May 17 '13 at 10:08
  • You need a way to define a logged in user. The easiest way for this is "a user that has done any activity for the last _n_ minutes". If you cannot incorporate that or a similar logic in your data model because you are not allowed to change it, you cannot complete this task. – CodeCaster May 17 '13 at 10:10

3 Answers3

1

you can have an extra column "Active" that will be updated everytime a user logs in. you can just take a count of that when you need online users.

shaz
  • 11
  • 2
  • 1
    Who will put the 'active' value back to inactive? I suggest using a 'last active' column and comparing the current time to that. Users that didn't explicitly logout and are inactive for, say, 5 minutes are considered not logged on. – Caramiriel May 17 '13 at 10:23
0

you should have a column in your members table called something like last_login_time. Then to know which users are currently logged in you can simply check that column for some actual period of time, like this

SELECT * FROM `members` WHERE `last_login_time` > DATE_SUB(NOW(), INTERVAL 5 MINUTE)
Arustamyan G.
  • 671
  • 6
  • 12
0

create a column in member table as login_time and logout_time use query to display logged in user

SELECT `user_name` From `table_name` WHERE `login_time` > `logout_time`
Sridhar
  • 32
  • 3