?php function IP_Blacklist($minimum = null, $maximum = null) { $ip = ip2long($_SERVER['REMOTE_ADDR']); if (is_null($minimum) === false) { $minimum = explode('.', $minimum); foreach ($minimum as $key => $value) { $minimum[$key] = ($value == '*') ? 0 : $value; } $minimum = ip2long(implode('.', $minimum)); if ($ip >= $minimum) { return false; } } if (is_null($maximum) === false) { $maximum = explode('.', $maximum); foreach ($maximum as $key => $value) { $maximum[$key] = ($value == '*') ? 255 : $value; } $maximum = ip2long(implode('.', $maximum)); if ($ip <= $maximum) { return false; } } return true; } ?> |
Usage $_SERVER['REMOTE_ADDR'] = 195.22.23.24:
IP_Blacklist('195.22.23.*'); // false, blacklisted IP_Blacklist('195.0.0.0', '195.255.255.255'); // false, blacklisted IP_Blacklist('195.22.23.25', '195.22.23.255'); // true, clean if (IP_Blacklist('195.22.23.*', '195.22.23.*') === false) { die('Nice try spammer.'); } ?> |
No comments:
Post a Comment