首页 » 后端 » PHP » 正文

PHP查询IP地址的地址位置:使用淘宝的IP地址查询接口

发布者:站点默认
2012/05/1 浏览数(1,688) 分类:PHP PHP查询IP地址的地址位置:使用淘宝的IP地址查询接口已关闭评论

用法:

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
        )

)

<完>

点击返回顶部
  1. 留言
  2. 联系方式