Home >Backend Development >PHP Tutorial >PHP uses Tencent IP sharing plan to obtain geographical location example sharing_PHP tutorial

PHP uses Tencent IP sharing plan to obtain geographical location example sharing_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:40:27878browse

Copy code The code is as follows:

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 and return
$result = curl_exec($ch);
$ result = mb_convert_encoding($result, "utf-8", "gb2312"); // Encoding conversion, otherwise garbled characters
curl_close($ch);
preg_match("@(.*)< ;/span>

@iU",$result,$ipArray);
$loc = $ipArray[1];
return $loc;
}
//Use
echo getIPLoc_QQ("183.37.209.57"); //You can get the address location of the IP address.
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/718618.htmlTechArticleCopy the code as follows: ?php function getIPLoc_QQ($queryIP){ $url = 'http://ip. qq.com/cgi-bin/searchip?searchip1='.$queryIP; $ch = curl_init($url); curl_setopt($ch,CURLOPT_ENCOD...
Statement:
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