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

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

 
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'].'市';
posted @ 2020-01-06 15:36  冬天不眠  阅读(500)  评论(0编辑  收藏  举报