From: Tim Starling Date: Fri, 14 Jul 2006 17:38:47 +0000 (+0000) Subject: That doesn't work... oh well, as long as no other module tries to use these constants... X-Git-Tag: 1.31.0-rc.0~56251 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=b3352f6b68a18fe4a620d329027bdcffc278b68f;p=lhc%2Fweb%2Fwiklou.git That doesn't work... oh well, as long as no other module tries to use these constants then the original scheme will be OK. --- diff --git a/includes/IP.php b/includes/IP.php index 371945c900..2691a15be9 100644 --- a/includes/IP.php +++ b/includes/IP.php @@ -7,22 +7,23 @@ * @License GPL v2 or later */ -class IP { - // Some regex definition to "play" with IP address and IP address blocks +// Some regex definition to "play" with IP address and IP address blocks + +// An IP is made of 4 bytes from x00 to xFF which is d0 to d255 +define( 'RE_IP_BYTE', '(25[0-5]|2[0-4]\d|1?\d{1,2})'); +define( 'RE_IP_ADD' , RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE . '\.' . RE_IP_BYTE ); +// An IP block is an IP address and a prefix (d1 to d32) +define( 'RE_IP_PREFIX' , '(3[0-2]|[12]?\d)'); +define( 'RE_IP_BLOCK', RE_IP_ADD . '\/' . RE_IP_PREFIX); - // An IP is made of 4 bytes from x00 to xFF which is d0 to d255 - const RE_BYTE = '(25[0-5]|2[0-4]\d|1?\d{1,2})'; - const RE_ADD = self::RE_BYTE . '\.' . self::RE_BYTE . '\.' . self::RE_BYTE . '\.' . self::RE_BYTE; - // An IP block is an IP address and a prefix (d1 to d32) - const RE_PREFIX = '(3[0-2]|[12]?\d)'; - const RE_BLOCK = self::RE_ADD . '\/' . self::RE_PREFIX; +class IP { /** * Validate an IP address. * @return boolean True if it is valid. */ public static function isValid( $ip ) { - return preg_match( '/^' . self::RE_ADD . '$/', $ip, $matches) ; + return preg_match( '/^' . RE_IP_ADD . '$/', $ip, $matches) ; } /** @@ -79,7 +80,7 @@ class IP { * @return array */ public static function toArray( $ipblock ) { - if(! preg_match( '/^' . self::RE_ADD . '(?:\/(?:'.self::RE_PREFIX.'))?' . '$/', $ipblock, $matches ) ) { + if(! preg_match( '/^' . RE_IP_ADD . '(?:\/(?:'.RE_IP_PREFIX.'))?' . '$/', $ipblock, $matches ) ) { return false; } else { return $matches;