Use ip2long() to convert dotted decimal to a real IP address. Then you can do ranges easily.
Just do ip2long() on the high and low range to get the value, then use those as constants in your code.
If you're familiar with subnet masking, you can do it like this:
// Deny 10.12.*.*
$network = ip2long("10.12.0.0");
$mask = ip2long("255.255.0.0");
$ip = ip2long($_SERVER{'REMOTE_HOST'});
if (($network & $mask) == ($ip & $mask)) {
die("Unauthorized");
}
Or if you're familiar with this format 10.12.0.0/16
:
// Deny 10.12.*.*
$network = ip2long("10.12.0.0");
$prefix = 16;
$ip = ip2long($_SERVER{'REMOTE_HOST'});
if ($network >> (32 - $prefix)) == ($ip >> (32 - $prefix)) {
die("Unauthorized");
}
You can turn these into functions and have very manageable code, making it easy to add IP addresses and customize the ranges.