Well, there are a few ways. If you want just the number of users viewing your site, you can count the number of files in the directory that your server uses to store $_SESSION files. Of course, that only works if you use $_SESSION variables instead of $_COOKIE variables.
Another way would be to add a field into your database. (Let's call it `active` and give it the ENUM('0', '1') field type -- '0' for when they are not logged in and '1' for when they are logged in. When a user successfully logs in, update that user's `active` field to '1'. And when they logout, update that user's `active` field to '0'. And then (to display a list of online users), just perform an SQL-Query that pulls all users from your user-data table with a '1' in their `active` field.