Posts: 81
Location: Cape Coral, Florida, United States
|
Let's say i want to check against 69.189.55.128/25
Of course the low range would be 69.189.55.128 and I am pretty sure the high range is 69.189.55.255
Currently I am using the following code:
Code:
function ip_allowed() {
$lo = ip2long("69.189.55.128");
$hi = ip2long("69.189.55.255");
$ip = ip2long($_SERVER['REMOTE_ADDR']);
return ($ip >= $lo && $ip <= $hi);
}
/* Check for valid IP address */
if (!ip_allowed()) exit("Access denied!");
I would like to use something more dynamic like:
Code:
function ip_allowed($val) {
list($ip_lo, $ip_mask) = split("/", $val);
$ip_lo = ip2long($ip_lo);
$ip_hi = ip2long(CALCULATED_VALUE_FROM_IP_MASK);
$ip_user = ip2long($_SERVER['REMOTE_ADDR']);
return ($ip_user >= $ip_lo && $ip_user <= $ip_hi);
}
/* Check for valid IP address */
if (!ip_allowed("69.189.55.128/25")) exit("Access denied!");
Does anybody know how to determine the maximum range by performing calculations on the ip mask?
__________________
Please login or register to view this content. Registration is FREE
FREE PHP scripts for your website!
|