PHP获取ip所在城市

版权声明:本人原创文章,转载时请保留所有权并以超链接形式标明文章出处 https://blog.csdn.net/qq_37138818/article/details/84100140

代码如下

function index(){
    $ip="218.26.XX.XXX";
    if($ip == ''){
        $url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json";
        $ip=json_decode(file_get_contents($url),true);
        $data = $ip;
    }else{
        $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
        $ip=json_decode(file_get_contents($url));   
        if((string)$ip->code=='1'){
           return false;
            }
        $data = (array)$ip->data;
        }
    
    var_dump($data);exit;
    }

更多的功能和插件 地址:https://www.kancloud.cn/he_he/thinkphp5

猜你喜欢

转载自blog.csdn.net/qq_37138818/article/details/84100140