You can use ajax for that... simply fire it every, let's say 5 seconds and call a PHP script with it that will update the users last online time / date... with this, you'll see who's "last_online" time/date was updated recently, which means they were online in the last 5 seconds...
|