用法:
http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址]
返回的数据格式:
JSON
示例代码:
<?php $ipAddr = '116.255.205.145'; $ipInfoApi = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ipAddr; $areaInfo = file_get_contents($ipInfoApi); $areaInfo = json_decode($areaInfo); print_r($areaInfo); #echo '当前IP所在国家:'.$areaInfo->data->country; ?>
示例代码返回的数据:
“//”及其后的文字是注释,返回的数据中是没有的哦~ ^_^
stdClass Object
(
[code] => 0 // 0:查询成功,1:查询失败
[data] => stdClass Object
(
[ip] => 116.255.205.145 // 待查询的那个IP地址
[country] => 中国
[country_id] => 86
[area] => 华中
[area_id] => 400000
[region] => 河南省
[region_id] => 410000
[city] => 郑州市
[city_id] => 410100
[county] => // 县
[county_id] => -1
[isp] => 景安计算机网络
[isp_id] => 1000152
)
)
<完>