通过ip 获取位置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41669475/article/details/80236006
function aa($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 aa("182.106.213.212");

猜你喜欢

转载自blog.csdn.net/qq_41669475/article/details/80236006
0条评论
添加一条新回复