If you have a login system setup in your script ..
You could create a new table in MYSQL called "active"
then when a user logs in, you could place the user in the active table
when they logout you culd remove them
and youll also need to include a script in your page header that will update the time the user loads the page in your active table, everytime they load a page.
then youll need to setup a CRON job that links to a php script to remove user's whos time hasnt been updated in .. well let's say 2400 seconds
This is what ive done with my site, and it works great.