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

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

WBOY
WBOYOriginal
2016-06-06 20:08:261160browse

?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
)
*/
 ?>
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
Previous article:PHP错误处理笔记Next article:PHP exec mysql return empty