Here is the code you can use all you need is mysql and php installed on your server
<?php
$Session_name = "default";
$host = "self explanatory";
$username = "put user name here";
$password = "db passowrd";
$database = "database";
$table = "online_users"; //make a table called online_users
if ($Session_name == "default") {
session_start();
}
else {
session_name("$Session_name");
session_start("$Session_name");
}
$SID = session_id();
$time = time();
$dag = date("z");
$nu = time()-900;
mysql_connect ($host, $username, $password) OR DIE ("Could not connect to MySQL");
mysql_select_db($database) OR DIE ("Can't select database.");
$sidcheck = mysql_query("SELECT count(*) FROM $table WHERE SID='$SID'");
$sid_check = mysql_result($sidcheck,0);
if ($sid_check == "0") {
mysql_query("INSERT INTO $table VALUES ('$SID','$time','$dag')");
} else {
mysql_query("UPDATE $table SET time='$time' WHERE SID='$SID'");
}
$count_users = mysql_query("SELECT count(*) FROM $table WHERE time>$nu AND day=$dag");
$users_online = mysql_result($count_users,0);
mysql_query("DELETE FROM $table WHERE time<$nu");
mysql_query("DELETE FROM $table WHERE day != $dag");
mysql_close();
if ($users_online == "1") {
echo "You are alone to view this page right now.\n";
}
else {
echo "There's $users_online people viewing this page right now.\n";
}
?>