不言不语

您现在的位置是: 首页 >  PHP

PHP

PHP获取地区函数

2022-06-03PHP
PHP获取地区函数,以及相关代码实例展示。
 function getCity($ip = '')
    {
        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
            $ip=json_decode(file_get_contents($url));
            if((string)$ip->code=='1'){
               return false;
            }
            $data = (array)$ip->data;
            $data['province']=$data['region'];
        }
        return $data;
    }

 

文章评论