how do you define 'logged into', given the web is a stateless environment (largely)?
most analysis treats active users as those that have visited a page or a site resource in the last X minutes.
once you have determined that this is a satisfactory method for you, you can then easily query your database of visits (which one assumes you keep for stats purposes).
alternatives (and not recommended) you could put some javascript on all your pages that creates a 5 second heartbeet with some cookie or other identifier, and you can use that to determine 'online' status.
either way, you need some sensible log of time of visit and identifier.
Interesting one from jpaddie, I think the cookie solution would only allow the page to check itself it is was posted back to the server. Reading between the lines it loks like you need a script that will run and tell you who is logged in now, you might run this at any time.
If your users need to authenticate to the site then you should be ok to have some kind of timestamp on the user record in the database which you can query. Each time any page is requested you would have to update the time stamp with the current time (you might even do this to implement a time out e.g. it's more than 20 mins since your last visit).
The session file stuff is interesting. Maybee just wordology here but sessions are held on 1 file per session basis not in one big file so you might be able to just look at the time stamps from an ls or dir to see who hasn't been here for 20 mins.
Now what I just said might not be true, you might have some custom session handler which does store all session info in a single file. You could even create your own session handler to hold session info in a database (good for web server farms) .
Also bear in mind that sessions are just that, you don't have to have any authentication to use them do your site could be all anonympus users, if you need to know the actual person who is logged in you will need to add that user name to the session details in ay case.
Hope this makes some sense !
by 'heartbeet' ([sic] I meant heart beat) i intended to imply that the javascript would asynchronously (AJAX) report back to the server to say that the user was still on-page.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.