0

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?

4
  • 1
    Your comment is misspelled. ;) Commented Sep 23, 2009 at 5:02
  • yes, that is the actual code I am using above Commented Sep 23, 2009 at 5:07
  • Was that meant to be a reply to my answer? Are you sure you're updating the right page? It doesn't seem to be throwing an error for my local page. Commented Sep 23, 2009 at 5:08
  • Is your code exactly as shown here? Might the 'bannedIPs' array be overwritten somehow? Commented Sep 23, 2009 at 5:21

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure you're passing in an array in your real page?
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
0

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;
    }
}

1 Comment

Please do not use the ereg*-functions (POSIX). As of PHP 5.3.0 this extension is deprecated - use the preg_*-functions instead (PCRE).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.