Home > Backend Development > PHP Tutorial > Use Taobao IP library to obtain user IP geographical location_PHP tutorial

Use Taobao IP library to obtain user IP geographical location_PHP tutorial

WBOY
Release: 2016-07-13 10:25:52
Original
1006 people have browsed it

Taobao has announced their IP library http://ip.taobao.com/, as well as the REST API interface, but the access frequency of each user must be less than 10qps, and the access method is: http://ip.taobao.com/service /getIpInfo.php?ip=[ip address string], the returned content is in json format. It has functions such as IP query and IP statistics. Information such as the number of IPs owned by major operators. Next, let’s introduce an example of obtaining IP:

Copy code The code is as follows:

/* *
 * Obtain IP geographical location through Taobao IP interface
 * @param string $ip
 * @return: string
 **/
 function getCity($ip)
 {
 $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
$ipinfo=json_decode(file_get_contents($url));
if($ipinfo->code=='1'){
return false;
}
$city = $ipinfo ->data->region.$ipinfo->data->city;
return $city;
}
header("Content-Type:text/html;charset=utf-8 ");
var_dump(getCity("112.234.69.189"));
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824921.htmlTechArticleTaobao announced their IP library http://ip.taobao.com/, as well as REST API interface, However, the access frequency of each user must be less than 10qps. Access method: http://ip.taobao.com/service/getIpInfo....
Related labels:
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