ip真实物理地址

参考一:ip-api.com/json/?lang=zh-CN&&ip=0.0.0.0 

        $ip = $request->ip();

        $url = 'http://ip-api.com/json/?lang=zh-CN&&ip='.$ip;

        $result = file_get_contents($url);

        $result=json_decode($result,true);//json格式的数据转换为对象、数组

        dump($result);     

*获取的数据默认语言可以随便设置,较精确,但是没有城市行政代码

参考二:pv.sohu.com/cityjson?ie=utf-8&&ip=0.0.0.0 

        $ip = $request->ip();

        $url = 'http://pv.sohu.com/cityjson?ie=utf-8&&ip='.$ip;

        $result = file_get_contents($url);//数组

        dump($result);     

*搜狐这个接口很稳定,也会返回城市代码500000,但是有时用4G或者其他情况返回的城市代码为CN,城市名为CHINA,不够精确

注意:【

            json_encode($result);//数组转为json
            json_encode($result, JSON_UNESCAPED_UNICODE);//汉字乱码问题
            json_decode($result,true);//json格式的数据转换为对象、数组

    】

原文地址:https://www.cnblogs.com/wkduxing/p/13627547.html