PHP 5.6.0beta1 released

filter_has_var

(PHP 5 >= 5.2.0)

filter_has_varVerifica se a variável é de um especificado tipo existente

Descrição

bool filter_has_var ( int $type , string $variable_name )

Parâmetros

type

Um dos INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, INPUT_ENV.

variable_name

Nome da variável a ser verificada.

Valor Retornado

Retorna TRUE em caso de sucesso ou FALSE em caso de falha.

add a note add a note

User Contributed Notes 4 notes

up
4
nanhe dot kumar at gmail dot com
1 year ago
Through this example i think you can better understand

    if ( !filter_has_var(INPUT_GET, 'email') ) {
        echo "Email Not Found";
    }else{
        echo "Email Found";
    }
    Output

    localhost/nanhe/test.php?email=1 //Email Found
    localhost/nanhe/test.php?email //Email Found
    http://localhost/nanhe/test.php //Email Not Found

Consider on second example

http://localhost/nanhe/test.php
$_GET['email']="info@nanhe.in";
if ( !filter_has_var(INPUT_GET, 'email') ) {
        echo "Email Not Found";
    }else{
        echo "Email Found";
    }
But output will be Email Not Found
up
3
drm at melp dot nl
5 years ago
Please note that the function does not check the live array, it actually checks the content received by php:

<?php
$_GET
['test'] = 1;
echo
filter_has_var(INPUT_GET, 'test') ? 'Yes' : 'No';
?>

would say "No", unless the parameter was actually in the querystring.

Also, if the input var is empty, it will say Yes.
up
0
Benjamin
2 months ago
filter_has_var fixes warning in Netbeans 7.3 when directly accessing $_GET["variable"]

Simple get and post functions I suggest:

function isGet( $value ) {
  if(  filter_has_var( INPUT_GET, $value )  ) {
    return true;
  }
  return false;
}

function get( $name )
{
  return filter_input( INPUT_GET , $name );
}
up
-1
Anonymous
4 years ago
To note: filter_has_var() is a bit faster than isset()
To Top