php禁止访问某个地区的IP

function checkIp()
{
    
    $ip = egetip();
    $oldIp = getcvar('iplist');
    if ($oldIp) {
        Header("Location:".'/404.html');
        exit;
    }
    
    $setIps = ReturnPublicAddVar("jinyong_area");
    $citys = [];
    if(!empty($setIps)) {
        if (strstr($setIps,'-')) {
            $citys = explode('-',$setIps);
        } else {
            $citys = [$setIps];
        }
        
        // print_r($citys);exit;
        
        $res = '';
        $res = file_get_contents("https://restapi.amap.com/v3/ip?key=7ad665ca654f32cb5c2e7363eeef36df56&ip=" . $ip);
        $res = json_decode($res, true);
        $jinzhi = $citys;
     
        if ($res['province'] && in_array($res['province'], $jinzhi)) {
            esetcookie('iplist',$ip, time() + 3600*12, 0);
            Header("Location:".'/404.html');
            exit;
        }
    }
    
   
}

 

你可能感兴趣的