You are here

function ip_ranges_check_range in IP Ranges 7

Same name and namespace in other branches
  1. 7.2 ip_ranges.module \ip_ranges_check_range()

Checks if the given ip-address matches the given range.

Parameters

$ip: Black- or whitelisted ip-address range.

$current_ip: Ip to be checked against the list, usually users current ip-address.

Return value

TRUE if the ip is on the list, FALSE if it is not.

2 calls to ip_ranges_check_range()
ip_ranges_check_ip in ./ip_ranges.module
Checks users ip first against the whitelist, then the blacklist if needed.
ip_ranges_form_validate in ./ip_ranges.admin.inc
Form validation handler for ip_ranges_form().

File

./ip_ranges.module, line 112

Code

function ip_ranges_check_range($ip, $current_ip) {
  $ip = explode('-', $ip);
  list($lower, $upper) = $ip;
  $lower_dec = (double) sprintf("%u", ip2long($lower));
  $upper_dec = (double) sprintf("%u", ip2long($upper));
  $ip_dec = (double) sprintf("%u", ip2long($current_ip));
  return $ip_dec >= $lower_dec && $ip_dec <= $upper_dec;
}