PHP Classes

File: counter.php

Recommend this page to a friend!
  Classes of Amer Hendy  >  PHP Visitor IP Address  >  counter.php  >  Download  
File: counter.php
Role: Class source
Content type: text/plain
Description: the class file
Class: PHP Visitor IP Address
Get the IP address of visitor even behind a proxy
Author: By
Last change:
Date: 6 years ago
Size: 2,437 bytes
 

Contents

Class file image Download
<?php
//////////////////////////////////////////////////////////////////
/// VISITORS IP LUNIX EGYPT ///
/// version :1 ///
/// author :Amer Hendy - TROJAN ///
/// Location:EGYPT ///
/// SITE:fb.com/amerhendytrojan ///
//////////////////////////////////////////////////////////////////
class visitors{
    function
__construct($visitors){
       
$this->visitors=$visitors;
       
$this->myip=$this->getUserIP();
    }
    function
getUserIP(){
       
$client = @$_SERVER['HTTP_CLIENT_IP'];
       
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
       
$remote = $_SERVER['REMOTE_ADDR'];

        if(
filter_var($client, FILTER_VALIDATE_IP)){
           
$ip = $client;
        }elseif(
filter_var($forward, FILTER_VALIDATE_IP)){
           
$ip = $forward;
    }else{
       
$ip = $remote;
    }
    return
$ip;
    }

    function
count_visitors(){
       
$a=explode("::",$this->visitors);
        if(
count($a)==0){
            return
0;
        }elseif(
count($a)==1){
            if(empty(
$a[0])){
                return
0;
            }else{
                return
1;
            }
        }else{return
count($a);}
    }
    function
see_all(){
       
$a=explode("::",$this->visitors);
        return
$a;
    }
    function
add(){
       
$a=explode("::",$this->visitors);
        if(
count($a)==0){
           
$newip=$this->myip;
        }elseif(
count($a)==1){
            if(empty(
$a[0])){$newip=$this->myip;}else{
               
$newip=$this->check_ip_db($this->myip,$a);
            }
        }else{
           
$newip=$this->check_ip_db($this->myip,$a);
        }
        return
$newip;
    }
    function
check_ip_db($ip,$array){
        if(
in_array($ip,$array)){
            return
implode("::",$array);
        }else{
           
$o= implode("::",$array);
            return
$o."::".$ip;
        }
    }

}
$mysqli=new mysqli("localhost","root",'',"emp");
$query=$mysqli->query("SELECT * FROM `testcounter` WHERE `id`='1'");
while(
$row=mysqli_fetch_array($query)){
    print
"id: ".$row['id']."<br />";
    print
"title: ".$row['title']."<br />";
    print
"content: ".$row['content']."<br />";
   
$visitors=$row['visits'];
}
$vol=new visitors($visitors);
$newip=$vol->add();
   
$in_query="UPDATE `testcounter` SET `visits` = '".$newip."' WHERE `id` = 1;";
    if(!
$mysqli->query($in_query)){print mysqli_error($mysqli);exit();}
?>

For more information send a message to info at phpclasses dot org.