調用外部接口獲取用戶ip地址


    //通過搜狐接口獲取用戶的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'].'市';

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM