tags:

views:

58

answers:

2

I used to use the function below for an array or IP's but now I have changes the IP array from this:

$bannedIPs = array('127.0.0.0','72.189.218.85'); // Banned IPs array

ipban($bannedIPs);

function ipban($bannedIPs) {
    if (in_array($_SERVER['REMOTE_ADDR'], $bannedIPs)) { 
     include ("site_banip.php");
     session_destroy();
     exit;
    } 
}

to this:

$config_item['bannedIPs'] = array('127.0.0.0','72.189.218.85'); // Banned IPs array

ipban($config_item['bannedIPs']);

function ipban($bannedIPs) {
    if (in_array($_SERVER['REMOTE_ADDR'], $bannedIPs)) { 
     include ("site_banip.php");
     session_destroy();
     exit;
    } 
}

Now I cannot get it to work though,

Warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\webserver\htdocs\includes\functions.inc.php on line 948

Is it possible to do what I am trying to do?

+1  A: 

change the second argument to be $config_item['bannedIPs'] and pass the $config_item to the function.

meder
Are you *sure* you're passing in an array in your *real* page?
meder
Ahh I just changed a lot of code around to use different classes and turned out the particular page with that array var is not included, sorry and thanks
jasondavis
A: 

Use something like this, it will be very flexible in the future if you need to add more IPs.

$whitelist = array(
    // ".*.32.255.255", // Sample
    // "63.76.53.255", // Sample
    // "46..*..*..*", // Sample
    // "46.32..*..*", // Sample
    // "46.32.255..*", // Sample
    // "46..**.255.255", // Sample
);

foreach($whitelist as $ip)
{
    if (ereg($ip, $_SERVER['REMOTE_ADDR']))
    {
        include ("site_banip.php");
        session_destroy();
        exit;
    }
}
Derek Gathright
Please do not use the ereg*-functions (POSIX). As of PHP 5.3.0 this extension is deprecated - use the preg_*-functions instead (PCRE).
Stefan Gehrig