Well, I'm not expert with PHP, but I would suggest creating an SQL table called onlineUsers or somthing like that. Then when users login a PHP script adds them to the table. When they logout, simply remove them from the list.
Something like:
<?php
//Log the user in
$con = mysql_connect("localhost","username","password");
mysql_query("INSERT INTO onlineUsers (username) VALUE ('$username')") //Assuming the user's username is stored in $username
?>
And on Logout:
<?php
//Clear Cookies, etc.
$con = mysql_connect("localhost","username","password");
mysql_query("DELETE FROM onlineUsers WHERE username = '$username'") //Assuming the user's username is stored in $username
?>