您现在的位置是:首页> 网站开发> PHP

PHP获取地区函数

  • 2801人已阅读
  • 时间:2018-11-22 06:56:13
  • 分类: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;
    }

 

Top