first, u must know how to use session functions / setcookie function.
then, everytime a user come to ur site, they will be given a session or cookie.
then, then write a function to add an entry into database when a session / cookie is generated.
use sql statement to select * from ur_table then count rows
u must implement some garbage collection function.
u must decide what are the time limit for a non-activity session to be counted as viewers of your site.