<?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();}
 
?>
 
 |