php uses Tencent ip sharing plan to get location sample sharing

  • 2020-12-18 01:46:59
  • OfStack


<?php
function getIPLoc_QQ($queryIP){    
$url = 'http://ip.qq.com/cgi-bin/searchip?searchip1='.$queryIP;    
$ch = curl_init($url);    
curl_setopt($ch,CURLOPT_ENCODING ,'gb2312');  
curl_setopt($ch, CURLOPT_TIMEOUT, 10);   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; //  Get data return   
$result = curl_exec($ch);    
$result = mb_convert_encoding($result, "utf-8", "gb2312"); //  Code conversion, otherwise messy code  
curl_close($ch);   
preg_match("@<span>(.*)</span></p>@iU",$result,$ipArray);    
$loc = $ipArray[1];    
return $loc;
 } 
// use 
echo getIPLoc_QQ("183.37.209.57"); // You can get IP The location of the address.    
?>


Related articles: