Latest web development tutorials

PHP filter_has_var () function

PHP Filter Reference Complete PHP Filter Reference

Definition and Usage

filter_has_var () function checks whether the specified input variable type exists.

If successful it returns TRUE, on failure returns FALSE.

grammar

filter_has_var(type, variable)

参数 描述
type 必需。规定要检查的类型。

可能的输入类型:

  • INPUT_GET
  • INPUT_POST
  • INPUT_COOKIE
  • INPUT_SERVER
  • INPUT_ENV
variable 必需。规定要检查的变量。


Examples

In this example, the input variable "name" is sent to the PHP page:

<?php
if(!filter_has_var(INPUT_GET, "name"))
{
echo("Input type does not exist");
}
else
{
echo("Input type exists");
}
?>

Output code is as follows:

Input type exists


PHP Filter Reference Complete PHP Filter Reference