PHP uses Sina interface to query IP to obtain geographical location example_PHP tutorial

WBOY
Release: 2016-07-13 10:40:29
Original
1050 people have browsed it

复制代码 代码如下:

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/718616.htmlTechArticle复制代码 代码如下: ?php function getIPLoc_sina($queryIP){ $url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json $ch = curl_init($url); curl_setopt($ch,CURL...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!