首页 > 其他 > 详细

调用外部接口获取用户ip地址

时间:2020-01-06 16:01:31      阅读:267      评论:0      收藏:0      [点我收藏+]
 
1
2
3
4
5
6
7
8
9
10
11
12
//通过搜狐接口获取用户的ip;
    $json file_get_contents(‘http://pv.sohu.com/cityjson?ie=utf-8‘);
    preg_match_all(‘/"cip"\s*:\s*"([^"]+)"/‘$json$result, PREG_SET_ORDER);
    if (empty($result)) {
        $this->error("未获取到用户ip!");
    }
    $ip $result[0][1];
    //调用淘宝接口获取城市;
    $res file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=$ip");
    $res = json_decode($res, true);
    //获取浏览用户所在城市;
    $m   $res[‘data‘][‘city‘].‘市‘;

调用外部接口获取用户ip地址

原文:https://www.cnblogs.com/syscn/p/12156621.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!