I\'m having trouble figuring out how I can count the number of logged-in users in my application.
What I have: When a user logs in, they get a sessi
Rather than a IsLoggedIn column, you should add a LastTimeSeen column. Any time a person visits a page you update the column:
UPDATE members SET LastTimeSeen = NOW() WHERE id = $the_user_id
Then to get how many people are on the site at any given moment you use the query:
SELECT COUNT(*) FROM members WHERE LastTimeSeen > DATE_SUB(NOW(), INTERVAL 5 MINUTE)
That shows how many people have viewed a page in the past 5 minutes, which is the best you're gonna get without a much more complicated solution.