HomePHP Validating IP Addresses with Filters in PHP 5
Validating IP Addresses with Filters in PHP 5
If you’re a PHP developer who wishes to learn how to take advantage of the solid functionality provided by the filter extension that comes with PHP 5, then look no further, because you’ve come to the right place. Welcome to the seventh part of a nine-part series that gets you started using the most useful validation filters included with this PHP library.
And now that you know what to expect from this group of articles, it's time to review the concepts discussed in the last installment. In that article I explained how to use the filter extension for validating URLs in a truly painless fashion.
Indeed, the combination of the "filter_var()" function and the FILTER_VALIDATE_URL filter allowed us to easily determine if certain portions of a given URL, such as its host, paths and query strings, were valid. You can surely appreciate this functionality when developing modules, classes, plug-ins, etc. that must perform some kind of strong validation on incoming data.
The filter extension comes armed with another handy filter, though, that permits you to check some common things, such as the IP addresses of client machines. Thus, assuming that you're interested in learning how to accomplish this task without suffering premature hair loss, in the next few lines I'm going to discuss in depth the use of the FILTER_VALIDATE_IP filter. As you'll see in a moment, it is quite easy to master.
Now, let's get rid of the preliminaries and start seeing how to get the most of this powerful PHP 5 filter. Let's jump in!