if you didn't want to use regular expressions, and the IPs in your IP array always started at the beginning of the IP, then you could do something like this:
PHP Code:
<?php
function checkIP($ip_to_match, $ip_array) {
// make sure this is an array before we use foreach
if (is_array($ip_array)) {
// loop through ip array
foreach ($ip_array as $ip) {
// first test if there is a match, then test if the match starts at the beginning
if (strpos($ip_to_match, $ip)===0) {
return true;
}
}
}
return false;
}
$ban_array = array(
'216.47.55.141',
'72.47.147',
'74.171',
'58'
);
if (checkIP($_SERVER['REMOTE_ADDR'], $ban_array)) {
echo "This page is not accessible.";
exit;
}
?>
:: modified from kelvin's suggestion below ::