The way to do it is to convert the IP address into a form where you can do comparisons on it.
The obvious way to do it would be to convert it to a 32-bit int, but ints in PHP are signed, so that won't work right. We can convert it to a string though, and do string comparisons...
function normalize_ip($ip) {
list($a, $b, $c, $d) = explode('.', $ip);
return sprintf('%03d%03d%03d%03d', $a, $b, $c, $d);
}
$ip = normalize_ip('193.214.1.123');
$start = normalize_ip('193.214.1.0');
$end = normalize_ip('193.214.1.255');
if ($ip >= $start && $ip <= $end) {
echo "IP is valid.";
}
else {
echo "IP is not in the allowed range.";
}
The normalize_ip function just takes the IP address, turns each octet into a three-digit number, and joins them into a 12-digit number. It's really a string but string comparisons are easy in PHP. DO NOT attempt to do math on that string, as it will cause it to turn into an int and it'll overflow (as a number it is too big for PHP to easily handle).