note 51660 added to function.ip2long

From: Date: Wed, 06 Apr 2005 22:29:54 +0000
Subject: note 51660 added to function.ip2long
Groups: php.notes 
Request: Send a blank email to php-notes+get-87620@lists.php.net to get a copy of this message
Here is a function that tells you if an ip address is in a CIDR range. However, the CIDR argument can be an array of CIDRs. This was created from other matchCIDR functions in the user notes. function matchCIDR($addr, $cidr) { // $addr should be an ip address in the format '0.0.0.0' // $cidr should be a string in the format '100/8' // or an array where each element is in the above format $output = false; if ( is_array($cidr) ) { foreach ( $cidr as $cidrlet ) { if ( matchCIDR( $addr, $cidrlet) ) { $output = true; } } } else { list($ip, $mask) = explode('/', $cidr); $mask = 0xffffffff << (32 - $mask); $output = ((ip2long($addr) & $mask) == (ip2long($ip) & $mask)); } return $output; } ---- Manual Page -- http://www.php.net/manual/en/function.ip2long.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51660 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51660&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51660&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51660&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51660&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51660&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51660&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87620) next »