It is very important input by users are validated before they are sent for processing. Not validating what users enter can lead to a very big security breach and could make your website susceptible to hackers. PHP has a large number of filters for validation and sanitization, but we’re only going to see that of the Email, URL and IP address.
Let’s take a look at these validation filters and how they work.
Validating Email:
Function :– filter_var($value, FILTER_VALIDATE_EMAIL)
<?php $email = "knowledgecorner@gmail.com"; if (filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "This ($email) email is valid."; } else { echo "This ($email) is not valid."; } ?>Validating URL:
Function – filter_var($value, FILTER_VALIDATE_URL)
<?php $url = 'knowledgecorner.com'; if (filter_var($url, FILTER_VALIDATE_URL)) { echo "This ($url) URL is valid."; } else { echo "This ($url) URL is not valid."; } ?>Validating IP address:
Function – filter_var($value, FILTER_VALIDATE_IP)
<?php $ip = '10.199.212.2'; if (filter_var($ip, FILTER_VALIDATE_IP)) { echo "This ($ip) IP address is valid."; } else { echo "This ($ip) IP address is not valid."; } ?>
No comments:
Post a Comment