代码如下:
PHP
function getIPLoc_sina($queryIP){
$url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.PHP?format=json&ip='.$queryIP;
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_ENCODING,'utf8');
curl_setopt($ch,CURLOPT_TIMEOUT,5);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true) ; // 获取数据返回
$location = curl_exec($ch);
$location = json_decode($location);
curl_close($ch);
$loc = "";
if($location===FALSE) return "";
if (empty($location->desc)) {
$loc = $location->province.$location->city.$location->district.$location->isp;
}else{ $loc = $location->desc;
}
return $loc;
}
echo getIPLoc_sina("183.37.209.57");
?>
function getIPLoc_sina($queryIP){
$url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.PHP?format=json&ip='.$queryIP;
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_ENCODING,'utf8');
curl_setopt($ch,CURLOPT_TIMEOUT,5);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true) ; // 获取数据返回
$location = curl_exec($ch);
$location = json_decode($location);
curl_close($ch);
$loc = "";
if($location===FALSE) return "";
if (empty($location->desc)) {
$loc = $location->province.$location->city.$location->district.$location->isp;
}else{ $loc = $location->desc;
}
return $loc;
}
echo getIPLoc_sina("183.37.209.57");
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。