function restrict_by_ip_role_check in Restrict Login or Role Access by IP Address 6.3
Same name and namespace in other branches
- 8.4 restrict_by_ip.module \restrict_by_ip_role_check()
- 6.2 restrict_by_ip.module \restrict_by_ip_role_check()
- 7.3 restrict_by_ip.module \restrict_by_ip_role_check()
Perform an IP restriction check for all roles belonging to the given user.
1 call to restrict_by_ip_role_check()
- restrict_by_ip_boot in ./
restrict_by_ip.module - Implementation of hook_boot().
File
- ./
restrict_by_ip.module, line 414 - 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_role_check(&$user) {
// Get all roles for the specified user
$result = db_query('select rid FROM {users_roles} where uid = %d', $user->uid);
$ip2check = _restrict_by_ip_get_ip();
// Check each role belonging to specified user
while ($row = db_fetch_object($result)) {
$rid = $row->rid;
$ranges = variable_get('restrict_by_ip_role' . $rid, '');
// Only check IP if an IP restriction is set for this role
if (strlen($ranges) > 0) {
$ipaddresses = explode(';', $ranges);
$match = FALSE;
foreach ($ipaddresses as $ipaddress) {
if (_restrict_by_ip_cidrcheck($ip2check, $ipaddress)) {
$match = TRUE;
}
}
if (!$match) {
unset($user->roles[$rid]);
}
}
}
}