On Thu, Sep 20, 2012 at 6:03 PM, Jim Lucas <li...@cmsws.com> wrote:
> On 09/20/2012 02:35 AM, Sebastian Krebs wrote:
>>
>> Plaseplease update... 5.1.6 is from 2006! I read the "it's required",
>> but I can't imagine _anything_ that it's worth it to use such an
>> extremely outdated, unsupported and therefore insecure and inefficient
>> version... You know: There are 3 (!) new minor versions available right
>> now (5.2, 5.3 and 5.4).
>>
>>
>> However: Regarding your concrete problem I guess you can use ip2long()
>>
>> if (ip2long($ip)) {
>
>
> I would suggest a modification to this.
>
> if ( ip2long($ip) !== false ) {
>
>
> I suggest this because IP to long will return negative numbers for half the
> IP range.  Therefor 50% of your possible results would be considered false
> when in fact they are valid IPs.
>
> See Example #2 on this page:
> http://php.net/manual/en/function.ip2long.php
>
>

First of all, I agree with Maciek that inet_pton is the way to go
because of IPv6.
But, there seems to be some wrong information in your reply which bothers me.
First of all, ip2long only returns negative numbers on 32bit systems,
not on 64bit (which most servers are nowadays).
Second, there's nothing wrong with the if, if(-5) is still true. The
only difference is that you can differentiate between IP 0.0.0.0 and
false. But IP 0.0.0.0 is not valid anyway.

- Matijn

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

Reply via email to