Re: [PHP] about PHP's filter_var function

2012-09-21 Thread Sebastian Krebs

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  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



Re: [PHP] about PHP's filter_var function

2012-09-20 Thread Jim Lucas

On 09/20/2012 10:00 AM, Matijn Woudt wrote:

On Thu, Sep 20, 2012 at 6:03 PM, 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 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...

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

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



Re: [PHP] about PHP's filter_var function

2012-09-20 Thread Sebastian Krebs

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



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



Re: [PHP] about PHP's filter_var function

2012-09-20 Thread Matijn Woudt
On Thu, Sep 20, 2012 at 6:03 PM, 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 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



Re: [PHP] about PHP's filter_var function

2012-09-20 Thread Sebastian Krebs

Am 20.09.2012 18:03, schrieb Jim Lucas:

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




No, negative numbers are "true" too. Only 0 is false, so '0.0.0.0' is 
the only edge case.





} else {
}

Regards,
Sebastian

Am 20.09.2012 11:14, schrieb lx:

Hello:
I want to use filter_var function by this way:

$ip = "192.168.0.1";

if( !filter_var($ip, FILTER_VALIDATE_IP) )
{
echo "IP is not valid";
}
else
{
echo "IP is valid";
}

I want to check the string $ip is IP address or not.but my PHP
version is
5.1.6.
and I know the filter_var requires at least PHP version 5.2.0.
so, Any other function in PHP 5.1.6 can slove this work and replace the
filter_var function ?

Thank you, I'm a new one, so I don't know much about PHP documentation.

By the way, The PHP version is required. so I can't upgrade it.









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



Re: [PHP] about PHP's filter_var function

2012-09-20 Thread 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.


- Tul

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



Re: [PHP] about PHP's filter_var function

2012-09-20 Thread Jim Lucas

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


} else {
}

Regards,
Sebastian

Am 20.09.2012 11:14, schrieb lx:

Hello:
I want to use filter_var function by this way:

$ip = "192.168.0.1";

if( !filter_var($ip, FILTER_VALIDATE_IP) )
{
echo "IP is not valid";
}
else
{
echo "IP is valid";
}

I want to check the string $ip is IP address or not.but my PHP version is
5.1.6.
and I know the filter_var requires at least PHP version 5.2.0.
so, Any other function in PHP 5.1.6 can slove this work and replace the
filter_var function ?

Thank you, I'm a new one, so I don't know much about PHP documentation.

By the way, The PHP version is required. so I can't upgrade it.







--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

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



Re: [PHP] about PHP's filter_var function

2012-09-20 Thread Sebastian Krebs
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)) {
} else {
}

Regards,
Sebastian

Am 20.09.2012 11:14, schrieb lx:

Hello:
I want to use filter_var function by this way:

 $ip = "192.168.0.1";

 if( !filter_var($ip, FILTER_VALIDATE_IP) )
 {
 echo "IP is not valid";
 }
 else
 {
  echo "IP is valid";
 }

I want to check the string $ip is IP address or not.but my PHP version is
5.1.6.
  and I know the filter_var requires at least PHP version 5.2.0.
so, Any other function in PHP 5.1.6 can slove this work and replace the
filter_var function ?

Thank you, I'm a new one, so I don't know much about  PHP documentation.

By the way, The PHP version is required. so I can't upgrade it.




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



Re: [PHP] about PHP's filter_var function

2012-09-20 Thread Vikash Kumar
You can use regex to check the
format: /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
You can also explode $ip on "." and check if every part is numeric and less
than 255.


On 20 September 2012 14:44, lx  wrote:

> Hello:
>I want to use filter_var function by this way:
>
> $ip = "192.168.0.1";
>
> if( !filter_var($ip, FILTER_VALIDATE_IP) )
> {
> echo "IP is not valid";
> }
> else
> {
>  echo "IP is valid";
> }
>
> I want to check the string $ip is IP address or not.but my PHP version is
> 5.1.6.
>  and I know the filter_var requires at least PHP version 5.2.0.
> so, Any other function in PHP 5.1.6 can slove this work and replace the
> filter_var function ?
>
> Thank you, I'm a new one, so I don't know much about  PHP documentation.
>
> By the way, The PHP version is required. so I can't upgrade it.
>