Home arrow PHP arrow Page 2 - Validating URL Protocols, Hosts and Paths with Filters in PHP 5

Review: the FILTER_VALIDATE_URL filter - PHP

When it comes to checking incoming data in web applications, PHP 5 provides developers with a huge arsenal of functions that permit them to perform this process in a pretty straightforward way. Indeed, checking integers and float numbers, IP and email addresses, alphabetic strings and so forth is a process that must be tackled frequently by programmers. Fortunately, validating data types is not a huge production with PHP.

TABLE OF CONTENTS:
  1. Validating URL Protocols, Hosts and Paths with Filters in PHP 5
  2. Review: the FILTER_VALIDATE_URL filter
  3. Validating URLs more strictly with the FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED constants
  4. Validating paths within URLs: the FILTER_FLAG_PATH_REQUIRED argument
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
August 19, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

If you havenít had the chance to read the previous chapter of the series, where I coded a few basic examples showing how to validate URLs using the FILTER_VALIDATE_URL filter, you'll find those examples listed below. Here they are:

(example on validating a well-formatted URL with the FILTER_VALIDATE_URL filter)

 

$url = 'http://www.devshed.com';

if(filter_var($url, FILTER_VALIDATE_URL) === FALSE) // displays The URL provided is valid.

{

echo 'The URL provided is not valid.';

}

else

{

echo 'The URL provided is valid.';

}

 

 

 

(example on validating a badly-formatted URL with the FILTER_VALIDATE_URL filter)

 

$url = 'http://';

if(filter_var($url, FILTER_VALIDATE_URL) === FALSE) // displays The URL provided is not valid.

{

echo 'The URL provided is not valid.';

}

else

{

echo 'The URL provided is valid.';

}

As you may recall, performing basic validation on URLs with the FILTER_VALIDATE_URL filter is a very simple process that should be easy for you to grasp. In the code samples listed above, the filter is used in its simplest version, meaning that itíll only check that the URLs being validated are well-formatted and nothing else.

As I mentioned in the introduction, however, it's possible to instruct the filter to analyze different portions of a URL, including its protocol, host and paths, thus performing a more strict validation process. So, assuming that youíre interested in learning how to accomplish these helpful tasks, in the section to come Iím going to discuss how to utilize the FILTER_VALIDATE_URL filter in a more useful manner.

As usual, to learn more on this specific topic, please click on the link that appears below and keep reading.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: