PHP判断IP是中国IP还是外国IP

获取IP的详情:

http://ip.taobao.com/service/getIpInfo.php?ip=(IP地址)

PHP获取方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//返回ip所在的区域 外国ip精确到国名
function getcposition($ip){
      
    try {
        $res1 file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=$ip");
        $res1 = json_decode($res1,true);
  
        if ($res1"code"]==0){
            return $res1['data']["country"].$res1['data'][ "region"].$res1['data']["city"]."_".$res1['data'][ "isp"];
        }else{
            return "未能获取";
        
    }catch (Exception $e){
        return "未能获取";
    }
}



白俊遥博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论