PHP filter_input() Function

❮ 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");
}
?>
Try it Yourself »

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 Values

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: The value of the variable on success, FALSE on failure, or NULL if the variable is not set
PHP Version: 5.2+

❮ Complete PHP Filter Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.