1. PHP Filters
PHP filters are used to validate and filter data
coming from insecure source like user input, web
services data, cookies and database query
results.
It validate and sanitizing data. Validation data
means data is in proper form or not and
sanitizing means remove any illegal character
form data
2. Why Use Filters
Almost all web applications depends
on external inputs and by using filter
you can be sure your application gets
correct input type
Invalid submitted data can lead to
security problems and break your
webpage!
3. Functions and Filters
Filter_var() :- filter a single variable with
specified filter flag
Filter_var_array() :- filter the several variable
with the same or different
filter.
Filter_input :- get one input variable and filter
it.
Filter_input_array :-get several input variable and
filter then with the same
or different filter.
Filter_id() :- return the filter id of specified of
filter name.
Filter_list() :- return a list of all supported
4. Fiter_var()
The below code use
FILTER_VALIDATE_INT flag to validate
integers
<?php
$int = 100;
if (!filter_var($int, FILTER_VALIDATE_INT) === false) {
echo("Integer is valid");
} else {
echo("Integer is not valid");
}
?>
IP address, EMAIL and URL can be validate using
FILTER_VALIDATE_IP, FILTER_VALIDATE_EMAIL and
FILTER_VALIDATE_URL,