Give each session a unique ID - if you're not already using sessions (which does this anyway).
Write them into a file / database (If using a file, make sure it's locked correctly otherwise race conditions could cause corruption).
Assume that anybody who hasn't hit a PHP page for 5 minutes or so has gone away.
So display or count all the ones who have hit a page in the last 5 minutes.
Somewhere you should also delete the old sessions from this table so it doesn't become excessively large.
Mark