Location: PHPKode > scripts > PHP Online Users > php-online-users/test.php
<?php
session_start();
$db_server = 'localhost';
$db_name = 'onlineusers';
$db_user = 'root';
$db_pass = '';

$LINK = mysql_connect($db_server,$db_user,$db_pass) or die("Can't connect to mysql server");
mysql_select_db($db_name,$LINK) or die("Unknown database");

$CURUSER = array(); //in this example i am holding loggined user data in CURUSER array

/*
Dummy record
$time = (time()+(3600*24*100));
setcookie('user','user 1',$time);
setcookie('user_id',1,$time);
*/

if (isset($_COOKIE['user']) && $_COOKIE['user'] != '' && isset($_COOKIE['user_id']) && is_numeric($_COOKIE['user_id'])){
	//you may want to validate your user record here
	$CURUSER['user'] = $_COOKIE['user'];
	$CURUSER['user_id'] = $_COOKIE['user_id'];
}

require("online.class.php");
$ONLINE = new whoIsOnline();
$ONLINE->setSessionTime(1); //5 mins check
$ONLINE->recordUser();
$ONLINE->cleanup(); //it is good to run this function by cron

if(isset($CURUSER['user_id']) && $ONLINE->isOnline($CURUSER['user_id'])) {
	echo 'User ', $CURUSER['user'], ' is online';
}
?>
Return current item: PHP Online Users