I know of a more.. entry-level method.
(With all respect to Fou-Lu)
You create a simple script that you can put on each page
, let's see if I can remember it all..
First you check if a user session exists, or something that lets you know the page is being accessed via someone you want to log as online. If it is, you then take that user's username / id /whatever you want to use, and put it in the table for online users with a timestamp
. Make sure you also allow for that user already being in the table for online users, in which case you would only want to update the timestamp not create another field.
The second step is with displaying the online users, where-ever that might be on your site (This part does not have to be on each page!). You get the results of the online user table, which may or may not contain outdated results, and compare the timestamp that was last updated when they loaded a page (This is what the first step is doing) with the current
timestamp. You can choose your own span of time for which they can be considered active, for example you may compare for timestamps that are 15 minutes old or less, or 10 minutes or less. Make sure you delete results that have become outdated in this moment as well, because although it would still only (providing it's working right) display the users that are current, you don't want the database to fill up with junk that is no longer needed.
For this, if you are unfamiliar with dealing with times in PHP, you might want to research that a little bit. Hopefully this is quite understandable though.