This forum uses its own session-handler, and session data is stored in the database, that way it is very simple to find out who's online and who isn't.
If you want to keep using the session handling of php itself (files), you can do it a little different. Two possible ways:
make a table with the info you want.
When a session is created place an entry in it for the user wich is online.
update that each time a script is requested and remove items wich haven't been changed x minutes.
another solution is to add a field to the table with users wich states his last page-request. Update that field for the current user each page request and then you can use a simple query to find out wich users have requested a page in the last x minutes and, effectively, are online.