Well the good thing about open source is you can always take a look at the code and see how others do it. So all you need to know is how to read code
Generally each visitor gets assigned a session that is tracked by a cookie or URL parameter - especially if they have to log in. So then all the software has to do is count “recent” sessions. One could stop counting a session when the visitor logs out or after a timeout period has elapsed.
And if you are looking for a PHP tutorial, Google is your friend - all you have to do is search for “online counter PHP” and the results lead you to:
Build a People Online Counter with PHP and MySQL
openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7