You are here

function _restrict_by_ip_cidrcheck in Restrict Login or Role Access by IP Address 7.3

Same name and namespace in other branches
  1. 6.3 restrict_by_ip.module \_restrict_by_ip_cidrcheck()
  2. 6.2 restrict_by_ip.module \_restrict_by_ip_cidrcheck()

Check ip address against a network in cidr notation. E.g: _restrict_by_ip_cidrcheck('192.168.10.100','192.168.10.0/24'); returns 1 _restrict_by_ip_cidrcheck('192.168.10.100','192.168.12.0/24'); returns 0

3 calls to _restrict_by_ip_cidrcheck()
restrict_by_ip_role_check in ./restrict_by_ip.module
Perform an IP restriction check for all roles belonging to the given user.
_restrict_by_ip_login in ./restrict_by_ip.module
Login function Checks the user's ip address on login If they are not restricted, or logging in from the appropriate address allow logon to continue. If not redirect to a designated page
_restrict_by_ip_validate_ip in ./restrict_by_ip.module
This function just makes sure the user input for the ip address section is valid.

File

./restrict_by_ip.module, line 607
Allows the admin to select which ip addresses role or a user can login from for this site Some of the code below is taken from the cck_ipaddress_module

Code

function _restrict_by_ip_cidrcheck($iptocheck, $ipslashcidr) {

  // Separate ip address and cidr mask
  $netmask = explode("/", $ipslashcidr);

  // Get valid network as long
  $ip_net = ip2long($netmask[0]);

  // Get valid network mask as long
  $ip_mask = ~((1 << 32 - $netmask[1]) - 1);

  // Get ip address to check as long
  $ip_ip = ip2long($iptocheck);

  // Mask ip address to check to get subnet
  $ip_ip_net = $ip_ip & $ip_mask;

  // Only returns 1 if the valid network

  //and the subnet of the ip address

  //to check are the same
  return $ip_ip_net == $ip_net;
}