<?php
$onlineip=egetip();
$ipinfo=json_decode(file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$onlineip),true);//将API的json格式解码保存到ipinfo变量
print_r($ipinfo);
?>
结果是:
Array ( [code] => 0 [data] => Array ( [ip] => 60.221.102.118 [country] => 中国 [area] => [region] => 山西 [city] => 临汾 [county] => XX [isp] => 联通 [country_id] => CN [area_id] => [region_id] => 140000 [city_id] => 141000 [county_id] => xx [isp_id] => 100026 ) )
Array ( [code] => 0 [data] => Array ( [ip] => 169.235.24.133 [country] => 美国 [area] => [region] => 加利福尼亚 [city] => XX [county] => XX [isp] => XX [country_id] => US [area_id] => [region_id] => US_104 [city_id] => xx [county_id] => xx [isp_id] => xx ) )