FengFeng
New Member
- Messages
- 59
- Reaction score
- 0
- Points
- 0
The code can geolocation the ip address.If it's a Chinese IP,you can get more detail in Chinese.Enjoy it.
via http://www.dyfeng.co.cc/2009/04/23/i...ress-comments/
Code:
<?php
function ip_query_function($ip){
$d = file_get_contents("http://www.iplocationtools.com/ip_query.php?ip=$ip&output=xml");
if (!$d)return false;
$answer = new SimpleXMLElement($d);
if ($answer->Status != 'OK')
return false;
$country_name = $answer->CountryName;
$region_name = $answer->RegionName;
$city = $answer->City;
if ($country_name=="China")
{
$c =file_get_contents("http://www.youdao.com/smartresult-xml/search.s?type=ip&q=$ip");
$answer = new SimpleXMLElement($c);
$location = $answer->product[0]->location;
$ip=$answer->product[0]->ip;
$return_ip="IP:".$ip." $city,$region_name,$country_name (".$location.")";
}else{
$return_ip="IP:".$ip." $city,$region_name,$country_name";
}
return $return_ip;
}
?>
via http://www.dyfeng.co.cc/2009/04/23/i...ress-comments/
Code:
<?php
function ip_query_function($ip){
$d = file_get_contents("http://www.iplocationtools.com/ip_query.php?ip=$ip&output=xml");
if (!$d)return false;
$answer = new SimpleXMLElement($d);
if ($answer->Status != 'OK')
return false;
$country_name = $answer->CountryName;
$region_name = $answer->RegionName;
$city = $answer->City;
if ($country_name=="China")
{
$c =file_get_contents("http://www.youdao.com/smartresult-xml/search.s?type=ip&q=$ip");
$answer = new SimpleXMLElement($c);
$location = $answer->product[0]->location;
$ip=$answer->product[0]->ip;
$return_ip="IP:".$ip." $city,$region_name,$country_name (".$location.")";
}else{
$return_ip="IP:".$ip." $city,$region_name,$country_name";
}
return $return_ip;
}
?>