THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP filter_input() Function

PHP Filter Reference PHP Filter Reference

Example

Check if the external variable "email" is sent to the PHP page, through the "get" method, and also check if it is a valid email address:

<?php
if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL)) {
    echo("Email is not valid");
} else {
    echo("Email is valid");
}
?>
Run example »

Definition and Usage

The filter_input() function gets an external variable (e.g. from form input) and optionally filters it.

This function is used to validate variables from insecure sources, such as user input.


Syntax

filter_input(type, variable, filter, options)
Parameter Description
type Required. The input type to check for. Can be one of the following:
  • INPUT_GET
  • INPUT_POST
  • INPUT_COOKIE
  • INPUT_SERVER
  • INPUT_ENV
variable Required. The variable name to check
filter Optional. Specifies the ID or name of the filter to use. Default is FILTER_DEFAULT, which results in no filtering
options Optional. Specifies one or more flags/options to use. Check each filter for possible options and flags

Technical Details

Return Value:

Returns the value of the variable on success, FALSE on failure, or NULL if the "variable" parameter is not set

PHP Version: 5.2.0+

PHP Filter Reference Complete PHP Filter Reference