function services_ipauth_ip_is_in_range in Services IP Authentication 6
Same name and namespace in other branches
- 7 services_ipauth.module \services_ipauth_ip_is_in_range()
Check if an IP address is in a certain range.
Parameters
string $ip The IP address to check.:
string $range The range in which the IP address must be.:
Return value
boolean TRUE if the IP address is within the range, FALSE otherwise.
1 call to services_ipauth_ip_is_in_range()
- _services_ipauth_authenticate_call in ./
services_ipauth.inc - Authenticate call.
File
- ./
services_ipauth.module, line 74 - Hook implementations and general API function for the IP Authentication module.
Code
function services_ipauth_ip_is_in_range($ip, $range) {
// Break up IP in quadrants.
$addr = explode(".", $ip);
$matches = FALSE;
// Multiple values are separated with commas so try each in turn.
$ip_ranges = explode(",", $range);
foreach ($ip_ranges as $ip_range) {
// Clear any whitespace, break into quads, then compare.
$ip_range = explode('.', trim($ip_range));
foreach ($ip_range as $index => $quad) {
if (!($matches = services_ipauth_ip_quad_matches($addr[$index], $quad))) {
// No match, escape this foreach and move on to next IP range.
break;
}
}
// If it matches, stop here and do login.
if ($matches) {
return $matches;
}
}
return FALSE;
}