One solution that works adequately uses sessions and MySQL (or other DB system).
Create a table with a varchar(32) field and an int field.
Each time someone requests a page, see if their session ID exists in the database, if it does, update the int field with the current timestamp. Otherwise, insert a new record to the db.
To count the current users online, select all rows from the DB where the tstamp >= the current time minus say 5 minutes.
HTH,
ucbones