Similar to celibate54's approach, but instead of using off/on, I use a timestamp field. The field is called something like "last on" and I update the time stamp whenever a user hits a page.
Then when I want to know how many users are online, I just check the table and query all those who have last been on since 10 minutes ago (you can change this to 5, 20, 60 minutes or whatever you like).
Since HTTP is a stateless protocol, someone could just walk away from the computer. How long do you want to wait before considering them "logged off?" How would you update the database after they walk away? These are kind of tricky problems to solve.
By using date and time, I can track whatever window I want (aka: 10 minutes) without worrying about the user having to log off. But the info is also handy for knowing when someone last visited a site. This can be handy for performance or stats measuring.