当前位置:首页 > PHP教程 > PHP常见问题

php利用新浪接口查询ip获取地理位置示例

复制代码 代码如下:

<?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");
?>


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!