On Tue, Jun 5, 2012 at 1:49 PM, jas <jason.ger...@gmail.com> wrote:
<snip>
>
>
> As stated previously using CIDR notation such as 192.168.0.0/24, 10.0.0.0/24
> perform validation on an IP existing within said subnet range.
>
> visiting ip: 192.168.0.22
>
> acl allow range: 192.168.0.0/24
> acl deny range: 0.0.0.0/24
>
> CIDR notation allows me to utilize shorthand notation for specifying a range
> of IP's
>
> In those two cases any ip within 192.168.0.0 - 192.168.0.255 is allowed
> while anything else residing between 0.0.0.0 - 255.255.255.255 is denied
>
> The problem is I can perform operations on CIDR ranges such as the
> following:
> 192.168.0.0/24
> 192.168.1.0/16
> 10.0.0.0/24
>
> But cannot use the traditional 0.0.0.0/24 because iplong() evaluates 0.0.0.0
> as false thereby invalidating a valid CIDR notation when evaluated as
>
> (ip2long($ip) || (~ip2long($mask))) + 1;
>
> From my own tests only 0.0.0.0/24 fails or as shown in the example code
> above
>
> (ip2long(0.0.0.0) || (~ip2long(24))) + 1;
>
> The class I am using to test with can be found at
> http://www.php.net/manual/en/function.ip2long.php#108812
>

First of all, as I suggested earlier, the class uses the single |,
which means bitwise OR, you're using ||, boolean OR.
Second, the class you're referring to is wrong. Using ip2long on 24 is
just not valid, you probably want to call ip2long('255.255.255.0')
instead, though it is probably easier to convert the 24 to the long
value.

 - Matijn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to