PHP | filter_has_var() function
Last Updated :
14 Feb, 2019
Improve
The filter_has_var() function is an inbuilt function in PHP which is used to check whether the variable available or not especially it checks if a variable of a specified input type exist or not. It returns True on success or False on failure.
Syntax:
php
Output: This example may not show "Input type exists" as output in online IDE as there is no option for sending parameter with the code. So run it somewhere on server or localhost. If the name input type defined and sent through GET method so !filter_has_var(INPUT_GET, "name") returning false and printing output as "Input type exists".
Example 2:
php
Output: This example will not show expected output in online IDE as they do not allow to run PHP code with GET parameters. So, run it on some other hosting server or in localhost. As email input type defined and sent through GET method so !filter_has_var(INPUT_GET, "email") returning false and printing output as "Email found".
References: http://php.net/manual/en/function.filter-has-var.php
bool filter_has_var( $type, $variable_name )Parameters: This function accepts two parameters as mentioned above and described below:
- type: It is the required parameter and used to specify the type of input to check. The possible input types are INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, INPUT_ENV.
- variable_name: It is the required parameter and used to specify the name of a variable which need to check.
<?php
// PHP program to illustrate
// filter_has_var() function
if(!filter_has_var(INPUT_GET, "name")) {
echo("Input type does not exist");
}
else {
echo("Input type exists");
}
?>
<?php
// PHP program to illustrate
// filter_has_var() function
if(!filter_has_var(INPUT_GET, "name")) {
echo("Input type does not exist");
}
else {
echo("Input type exists");
}
?>

<?php
if (!filter_has_var(INPUT_GET, "email")) {
echo("Email not found");
} else {
echo("Email found");
}
?>
<?php
if (!filter_has_var(INPUT_GET, "email")) {
echo("Email not found");
} else {
echo("Email found");
}
?>
