New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more ip validation #78
Conversation
|
|
||
| // This validates without regard to reserved or private ranges in both v4 and v6 | ||
| if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === false) { | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about changing it to something like
if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)) {
return true;
}
return false;Is there any reason you didn't do that ? Just my suggestion, you should hear what @pmjones thinks about this before doing the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I was just attempting to be explicit. I don't imagine there is an IP Address that could return and be considered a false, but the way I wrote it ensures that cannot happen.
Thoughts?
Jarvis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter_var is an odd duck - like strcmp 0 might be a perfectly legal return and PHP does... odd things with strings that start with 0
it's generally better to do an exact === check, since that is actual failure for the filter, not just a value PHP would consider "empty " as the return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
I read through the code. This looks like a good enhancement. |
|
Thanks @BallisticPain for submitting, and everyone else for reviewing. :-) |
Adds validation for v4 and v6 through 'ip'
Adds validation for v6 through 'ipv6'
Updates validation for v4 by using filter_var instead of ip2long