Home > php教程 > php手册 > 淘宝IP地址所在地的调用(PHP)

淘宝IP地址所在地的调用(PHP)

WBOY
Release: 2016-06-06 20:08:26
Original
1135 people have browsed it

?php/** * http:/wdot.cc/ * 获取 IP 地理位置 * 淘宝IP接口 * @Return: object */function getCity($ip){$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;$ip=json_decode(file_get_contents($url));if((string)$ip-code=='1'){ return false;

<?php /**
 * http:/wdot.cc/
 * 获取 IP  地理位置
 * 淘宝IP接口
 * @Return: object
 */
function getCity($ip)
{
$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
$ip=json_decode(file_get_contents($url));
if((string)$ip->code=='1'){
  return false;
  }
return $ip->data;
}
 $arr=getCity('124.71.240.1');
 print_r($arr);
/*
 返回的数据
 stdClass Object
(
    [country] => 中国
    [country_id] => CN
    [area] => 华北
    [area_id] => 100000
    [region] => 北京市
    [region_id] => 110000
    [city] => 北京市
    [city_id] => 110000
    [county] => 
    [county_id] => -1
    [isp] => 中电华通
    [isp_id] => 100022
    [ip] => 124.71.240.1
)
*/
 ?>
Copy after login
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template