Re: about PHP's filter_var function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 20.09.2012 19:54, schrieb Jim Lucas:
On 09/20/2012 10:00 AM, Matijn Woudt wrote:
On Thu, Sep 20, 2012 at 6:03 PM, Jim Lucas<lists@xxxxxxxxx>  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


After some testing, I stand corrected.  Wow, I wonder where I ran into
the issue of negative numbers equating to false.  while loops maybe...

Strange.  I must have ran into this issue years ago.  I have always
performed strict (===) comparisons because I thought PHP would equate
negative numbers as false.

Learn something new every day...


You can find the full matrix here: http://php.net/types.comparisons

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux