php 以IP的形式获取访问者的地理位置

<?php
header('Content-Type:text/html;charset=utf-8');
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, );
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->city.$location->district.$location->isp;
}else{ $loc = $location->desc;
}
return $loc;
}
echo getIPLoc_sina("211.161.160.126");
?>
上一篇:rmdir&rm


下一篇:Java - 26 Java 数据结构