Strengthening validation: validating again in PHP
As mentioned previously, client-side validation should always be accompanied by server-side validation. If users turn off JavaScript on their browser and there is no server-side validation, then they can enter whatever they want. This could lead to disastrous results like your database being compromised and so on.
This recipe will go through the validation methods and functions available in PHP, which we can use to validate the data.
Getting ready
Create a new folder named Recipe7
inside the Chapter5
directory .
Note
Make sure your version of PHP is >5.2. We will be using filter functions that are available only after PHP >=5.2
How to do it...
Create a file named
index.php
inside the newly-createdRecipe7
folder. Create a form with different type of fields for entering strings, numbers, e-mail addresses, and website addresses.<html> <head> <title>Server Side validation</title> <style type="text/css">...