note 14413 deleted from function.ip2long by sniper

From: Date: Sat, 20 Sep 2003 07:51:26 +0000
Subject: note 14413 deleted from function.ip2long by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-56802@lists.php.net to get a copy of this message
Note Submitter: webmaster at mail.bg ---- If you want to check if an IP is within a specified network you can use the following function: # # IP_match($network, $mask, $ip); # # FUNCTION to check # if an IP is within the specified mask. # function IP_match($network, $mask, $ip) { $ip_long=ip2long($ip); $mask_long=ip2long($network); # # Convert mask to divider # if (is_integer($network)) { /// 212.50.13.0/27 style mask (Cisco style) $divider=2^(32-$mask); } else { /// 212.50.13.0/255.255.255.0 style mask $divider=(2^32-ip2long($mask)); } # # Test is IP within specified mask # if ( floor($ip_long/$divider) == floor($mask_long/$divider)){ # match - this IP is within specified mask return true; } else { # fail - this IP is NOT within specified mask return false; } }

« previous php.notes (#56802) next »