|
|
|
|
|
|
| |
Type: class
Version: 1.0
Requires:
Author: the mighty Indian
|
<?php
/*
This very simple class enables you to track number of visitors online in
an easy and accurate manner. It's free for all purposes, just please don't
claim you wrote it. If you have any problems, please feel free to contact me.
Also if you use it, please send me the page URL.
Example usage:
include_once ("usersOnline.class.php");
$visitors_online = new usersOnline;
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";
}
Important: You need to create database connection and select database before creating object!
--------------------------------------------
Table 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 ;
*/
class usersOnline {
var $timeout = 600;
var $count = 0;
function usersOnline () {
$this->timestamp = time();
$this->ip = $this->ipCheck();
$this->new_user();
$this->delete_user();
$this->count_users();
}
function ipCheck() {
/*
This function checks if user is coming behind proxy server. Why is this important?
If you have high traffic web site, it might happen that you receive lot of traffic
from the same proxy server (like AOL). In that case, the script would count them all as 1 user.
This function tryes to get real IP address.
Note that getenv() function doesn't work when PHP is running as ISAPI module
*/
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}
elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
}
elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
}
elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function new_user() {
$insert = mysql_query ("INSERT INTO useronline(timestamp, ip) VALUES ('$this->timestamp', '$this->ip')");
}
function delete_user() {
$delete = mysql_query ("DELETE FROM useronline WHERE timestamp < ($this->timestamp - $this->timeout)");
}
function count_users() {
$count = mysql_num_rows ( mysql_query("SELECT DISTINCT ip FROM useronline"));
return $count;
}
}
?> | | |
|
| Simple database class Categories : PHP, PHP Classes, MySQL, Databases | | | Link Manager for Link Exchangers Categories : PHP, PHP Classes, Databases, MySQL, CURL | | | PHP Transfer data from text file to Mysql Table Categories : PHP, PHP Classes, Filesystem, Databases, MySQL | | | A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | Simple Mini Poll class library (SimPoll) Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs | | | Powerful php/mysql Pagination for up to 6 URL Params Categories : PHP, PHP Classes, Databases, MySQL, Navigation | | | MySQL Handler Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes | | | Simple usersOnline class - keep track of how many users are online on your site Categories : PHP, PHP Classes, Databases, MySQL | | | PHP Object Example of the Perl DBI with MySQL Categories : PHP, PHP Classes, MySQL, Databases, Perl | | | PostGreSQL and MySQL 2 in 1 db Manager Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL | | | Password reminder Categories : PHP, PHP Classes, Databases, MySQL, Mail | | | Identify and log search engine access (spiders, robots, etc.) to a page. Categories : HTTP, Environment Variables, PHP, MySQL, Databases | |
|
|