Wednesday, August 20, 2008

User Online Class

Description:

This very simple class enables you to track number of visitors online in an easy and accurate manner.

Main features include:
  • Automatic insertion of new user
  • Automatic database cleanup
  • Check if user is coming behind proxy server (this helps in script accuracy)
  • Display of users online
  • Error reporting

DATABASE STRUCTURE
CREATE TABLE
`useronline` (
`
id` int(10) NOT NULL auto_increment,
`
ip` varchar(15) NOT NULL default '',
`
timestamp` varchar(15) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `id`(`id`)
)
TYPE=MyISAM COMMENT='' AUTO_INCREMENT=1 ;
?>



PHP CODE :
include_once ("usersOnline.class.php");
$visitors_online = new usersOnline();

if (
count($visitors_online->error) == 0) {

if (
$visitors_online->count_users() == 1) {
echo
"There is " . $visitors_online->count_users() . " visitor online";
}
else {
echo
"There are " . $visitors_online->count_users() . " visitors online";
}
}
else {
echo
"Users online class errors:
    \r\n";
    for (
    $i = 0; $i < count($visitors_online->error); $i ++ ) {
    echo
    "
  • " . $visitors_online->error[$i] . "
  • \r\n"
    ;
    }
    echo
    "
\r\n"
;

}
?>

No comments: