Visitor Details Using PHP

Visitor Details Using PHP

Visitor Details Using  PHP : -

This post  help you finding visitor detail using php without any third party library, for your website.You can    fiend your visitor ip,browser name,browser version ,devices, operating  system and much more

make visitor.php and put this code :-

 


<?php 
class visiter{
	//  function of validet visiter
	function visiter_detail() 
    { 
    $u_agent = $_SERVER['HTTP_USER_AGENT']; 

	function mobile(){
    $data = array(
        '/iphone/i' => 'iPhone', 
        '/ipod/i' => 'iPod', 
        '/ipad/i' => 'iPad', 
        '/android/i' => 'Android', 
        '/blackberry/i' => 'BlackBerry', 
        '/webos/i' => 'Mobile'
    );

    //Return true if Mobile User Agent is detected
    foreach($data as $mk => $mv){
        if(preg_match($mk, $_SERVER['HTTP_USER_AGENT'])){
            return $mv;
        }
    }
    //Otherwise return false..  
    return false;
}

              function computer()
                          {
	                   $data= array(
	                    '/windows nt 6.2/i'     =>  'Windows 8',
                        '/windows nt 6.1/i'     =>  'Windows 7',
                        '/windows nt 6.0/i'     =>  'Windows Vista',
                        '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
                        '/windows nt 5.1/i'     =>  'Windows XP',
                        '/windows xp/i'         =>  'Windows XP',
                        '/windows nt 5.0/i'     =>  'Windows 2000',
                        '/windows me/i'         =>  'Windows ME',
                        '/win98/i'              =>  'Windows 98',
                        '/win95/i'              =>  'Windows 95',
                        '/win16/i'              =>  'Windows 3.11',
                        '/macintosh|mac os x/i' =>  'Mac OS X',
                        '/mac_powerpc/i'        =>  'Mac OS 9',
                        '/linux/i'              =>  'Linux',
                        '/ubuntu/i'             =>  'Ubuntu',
	);
	
	    foreach($data as $ck => $cv){
        if(preg_match($ck, $_SERVER['HTTP_USER_AGENT'])){
            return $cv;
        }
    }
    //Otherwise return false..  
    return false;
	
	
}

    
	// finding browser name 
	function browser()
{
	$data = array (
	
	                    '/msie/i'       =>  'Internet Explorer',
                        '/firefox/i'    =>  'Firefox',
						'/Chrome/i'     =>  'Chrome',
                        '/safari/i'     =>  'Safari',
                        '/opera/i'      =>  'Opera',
                        '/netscape/i'   =>  'Netscape',
                        '/maxthon/i'    =>  'Maxthon',
                        '/konqueror/i'  =>  'Konqueror',
                        '/mobile/i'     =>  'Handheld Browser'
	
	);
	
	    foreach($data as $bk => $bv){
        if(preg_match($bk, $_SERVER['HTTP_USER_AGENT'])){
            return $bv;
        }
    }
    //Otherwise return false..  
    return false;
   }
	
	
	
	// finding device and os
	$mb=mobile();
	$pc=computer();

	if($mb !="")
	{
	$os= $mb;
	$device="phone";
	}
	elseif($pc !=""){
		$os= computer();
		$device= "computer";
	}
	
	// finding browser name
	$browser= browser();
	
	
	
	 // finally get the correct version number
    $known = array('Version', $browser, 'other');
    $pattern = '#(?' . join('|', $known) .
    ')[/ ]+(?[0-9.|a-zA-Z.]*)#';
    if (!preg_match_all($pattern, $u_agent, $matches)) {
        // we have no matching number just continue
    }
	
	 // see how many we have
    $i = count($matches['browser']);
    if ($i != 1) {
        //we will have two since we are not using 'other' argument yet
        //see if version is before or after the name
        if (strripos($u_agent,"Version") < strripos($u_agent,$browser)){
            $version= $matches['version'][0];
        }
        else {
            $version= $matches['version'][1];
        }
    }
    else {
        $version= $matches['version'][0];
    }
    
    // check if we have a number
    if ($version==null || $version=="") {$version="?";}
	
	
	//finding domane
	$domen = $_SERVER['HTTP_HOST'];
	
	// finding full url
	$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	
	// calling ip function
	$ipdat=$this->getip();
	
	$ip= $ipdat['ip'];
	$iptype=$ipdat['type'];
	
	//finding host name
	$hostname = gethostbyaddr($ip);

	//finding server name 
	$servername = $_SERVER['SERVER_NAME'];
	
	// finding server request time and date
	
	date_default_timezone_set('asia/kolkata');
    $date = date(date("Y:m:d h:i:s"),strtotime($_SERVER['REQUEST_TIME']));
	
    return array(
        'userAgent' => $u_agent,
        'bname'     => $browser,
		'bv'        => $version,
        'os'        => $os,
		'device'    => $device,
		'ip'        => $ip,
		'iptype'    => $iptype,
		'url'       => $url,
		'hostname'  =>$hostname,
		'servername'=>$servername,
		'date'      =>$date,
		'domane'    =>$domen,
    );
}
 
//finding clint real ip 
	

       function getip(){
		   
        $ipaddress = ''; 
		if (isset($_SERVER['HTTP_X_REAL_IP']))
		{
            $ipaddress = $_SERVER['HTTP_X_REAL_IP'];
			$type= "real";
        }
        else if (isset($_SERVER['HTTP_CLIENT_IP']))
		{
            $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
			$type= "real";
		}
        else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
		{
			
			 $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
			 $type= "feck";
		}
           
        else if(isset($_SERVER['HTTP_X_FORWARDED']))
		{
		  $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
          $type= "feck";		  
			
		}
          
        else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
		{
		$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];	
		$type= "feck";	
		}
            
        else if(isset($_SERVER['HTTP_FORWARDED']))
		{
		$ipaddress = $_SERVER['HTTP_FORWARDED'];	
		$type= "feck";	
		}
            
        else if(isset($_SERVER['REMOTE_ADDR']))
		{
		$ipaddress = $_SERVER['REMOTE_ADDR'];	
		$type= "real";	
		}
            
        else{
			$ipaddress = 'UNKNOWN';
			$type= "feck";	
		}
        
        $data =array("ip"=>$ipaddress,"type"=>$type);		
        
        return $data;
    }
}// class end hair


$visiter = new visiter();

$data = $visiter->visiter_detail();
echo"<pre>";
print_r($data);

?>

Download Here

Total Coments (0)