You Are Here: Home »   Code

Code Library - php

Wildcard IP Deny - (1,854 views)


<?

$_allow_ip 
= array('*.*.*.*');
$_deny_ip = array('123.456.789.*');
$_ip $REMOTE_ADDR;
$_allowed false;

foreach(
$_allow_ip as $_a_ip){
        
$_a_ip str_replace('.','\.',$_a_ip);
        
$_a_ip str_replace('*','[0-9]{1,3}',$_a_ip);
        
$_a_ip str_replace('?','[0-9]{1}',$_a_ip);

        if(
ereg("^{$_a_ip}$"$_ip)) $_allowed true;

     }

if(!
$_allowed){
    echo (
"No Access - Banned : $_ip");
    exit();

    
$_allowed true;
}

foreach(
$_deny_ip as $_d_ip){
        
$_d_ip str_replace('.','\.',$_d_ip);
        
$_d_ip str_replace('*','[0-9]{1,3}',$_d_ip);
        
$_d_ip str_replace('?','[0-9]{1}',$_d_ip);

        if(
ereg("^{$_d_ip}$"$_ip)) $_allowed false;
     }
if(!
$_allowed){
    echo (
"No Access - Banned : $_ip");
    exit();
}

?>