WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables Click here to Update Your Picture
lalith nayak
Date : Jan 31st 2006
Grade : 3 of 5 (graded 4 times)
Viewed : 7834
File : No file for this code example.
Images : No Images for this code example.
Search : More code by lalith nayak
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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;
    }

}
?> 



YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
MySQL database class
Categories : PHP, MySQL, Databases, PHP Classes
TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
Identify and log search engine access (spiders, robots, etc.) to a page.
Categories : HTTP, Environment Variables, PHP, MySQL, Databases
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
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
Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
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