php根据IP获取所在省份-淘宝api接口

这里用的file_put_contents,你也可以用别的,直接怼代码:

//拼接传递的参数
$ip = '175.12.53.12'
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Content-type:application/x-www-form-urlencoded\r\n",
)
);
//获取Ip所属位置
$context = stream_context_create($opts);
$fp = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip, false, $context);
$addrInfo = json_decode($fp, true);
var_dump($addrInfo);

返回的数据样式为:

array(2) { ["code"]=> int(0) ["data"]=> array(13) { ["ip"]=> string(12) "175.12.53.12" ["country"]=> string(6) "中国" ["area"]=> string(0) "" ["region"]=> string(6) "湖南" ["city"]=> string(6) "长沙" ["county"]=> string(2) "XX" ["isp"]=> string(6) "电信" ["country_id"]=> string(2) "CN" ["area_id"]=> string(0) "" ["region_id"]=> string(6) "430000" ["city_id"]=> string(6) "430100" ["county_id"]=> string(2) "xx" ["isp_id"]=> string(6) "100017" } }

 

转载于:https://www.cnblogs.com/wxdblog/p/8891482.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值