Page 1 of 1

Which users are logged in

Posted: Tue Apr 12, 2005 4:31 am
by thesimon
Hi,

I have a few project where users log in to a secure area, this is just a basic login where the password and username is checked against what is in the database.

I would like other users to be able to see who else is online. How is it possible to know which users from the users table in the database are currently logged in?

Thanks,
Simon

Posted: Tue Apr 12, 2005 4:35 am
by Chris Corbyn
Have a column in your database.

ENUM columns type, with values 0 or 1 for example.

If logged in set it to 1, otherwise set it to 0.

The just use MySQL's COUNT() function to get all the records where logged_in = '1'.

That should do it ;-)

Posted: Tue Apr 12, 2005 4:39 am
by hongco
you might want to consider who is online in a interval of time.
Some users might actually leave your website without logging out and come back in about a month; thus, they can't be logged in from the day they left until a month later :D

Posted: Tue Apr 12, 2005 4:44 am
by thesimon
thanks d11wtq, however as hongo said some of the users may fail to logout, thus the record wont change back, are any ideas to find out whos sessions are still running.thanks,
Simon

Posted: Tue Apr 12, 2005 4:55 am
by n00b Saibot
update their activity in a log somewhere and when that last act is sufficient amount of time say 5 mins. old then logout the user. this approach is pretty much used all the time.

Posted: Tue Apr 12, 2005 5:15 am
by CoderGoblin
Look at article Who is online