Re: about PHP's filter_var function

From: Date: Thu, 20 Sep 2012 17:04:58 +0000
Subject: Re: about PHP's filter_var function
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-319163@lists.php.net to get a copy of this message
Am 20.09.2012 18:17, schrieb Maciek Sokolewicz:
On 20-09-2012 18:03, Jim Lucas 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 would actually suggest using inet_pton() instead of ip2long, since it can also handle IPv6 adresses, not only v4 which people here seem to think are the only ones in use on this planet. And I agree with Jim that you really should use a strict equality check in this case.
IPv6 is a valid point, but inet_pton() triggers a warning in case of invalid addresses, which makes it quite useless for validation in my eyes. Also it's not available on windows before 5.3 And the strict comparison feels ... a little bit to much. Of course depending on the use-case, I would treat 0.0.0.0 as invalid too.
- Tul


« previous php.general (#319163) next »