Typical script to count the users 'online':
<?php
$timeoutseconds = 300;
$timestamp = time();
$timeout = $timestamp - $timeoutseconds;
mysql_connect();
mysql_select_db('users');
$insert = mysql_query(
"INSERT INTO online VALUES ('$timestamp', '$REMOTE_ADDR', '$PHP_SELF')");
$delete = mysql_query(
"DELETE FROM online WHERE timestamp < $timeout");
$result = mysql_query(
"SELECT DISTINCT ip FROM online WHERE file = '$PHP_SELF'");
$users = mysql_num_rows($result);
?>