1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

Monday, July 13, 2009

PHP program for trace remote IP address

This program helps you to trace the IP address of u'r visitor
class IPDetails{
var $ip;
var $countryName;
var $countryCode;
var $status;
var $regionCode;
var $regionName;
var $city;
var $zip;
var $latitude;
var $longitude;
var $gmtOffset;
var $dstOffset;

function collectIPDetails($ip){
$proxy = "192.168.0.6:3128";
$addr = "http://www.ipinfodb.com/ip_query.php?ip=$ip&output=xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $addr);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPGET,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$pg = curl_exec($ch);
if($pg){
$data = new SimpleXMLElement($pg);
$this->ip = $data->Ip;
$this->countryName = $data->CountryName;
$this->countryCode = $data->CountryCode;
$this->status = $data->Status;
$this->regionCode = $data->RegionCode;
$this->regionName = $data->RegionName;
$this->city = $data->City;
$this->zip = $data->ZipPostalCode;
$this->latitude = $data->Latitude;
$this->longitude = $data->Longitude;
$this->gmtOffset = $data->Gmtoffset;
$this->dstOffset = $data->Dstoffset;
}
}
}
$dt=new IPDetails();
$ip = $_SERVER['REMOTE_ADDR'];
$dt->collectIPDetails($ip);
echo $dt->countryName;
echo $dt->ip;
?>

1 comment:

  1. This information i searched & thanks for this information. I normally use the website to cchk the ip address from ip-detail.com

    ReplyDelete

Related Posts with Thumbnails