©
Ce document utilise Manuel du site Web PHP chinois Libérer
(PHP 5 >= 5.2.0, PHP 7)
filter_has_var — Checks if variable of specified type exists
$type
, string $variable_name
)
type
One of INPUT_GET
, INPUT_POST
,
INPUT_COOKIE
, INPUT_SERVER
, or
INPUT_ENV
.
variable_name
Name of a variable to check.
成功时返回 TRUE
, 或者在失败时返回 FALSE
。
[#1] dezlov [2015-07-30 13:12:10]
For people who are wondering whether "magic_quotes_gpc" has any affect on "filter_input" operation, here is an extract from a PHP source file:
* As the input filter acts on input data before the magic quotes function mangles data, all access through the filter() function will not have any quotes or slashes added - it will be the pure data as send by the browser.
So when using this function, there is no need to strip the slashes when "magic_quotes_gpc" is enabled.
[#2] Benjamin [2014-01-23 23:25:40]
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 );
}
[#3] nanhe dot kumar at gmail dot com [2013-03-06 14:15:27]
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
[#4] Anonymous [2009-05-21 02:28:30]
To note: filter_has_var() is a bit faster than isset()
[#5] drm at melp dot nl [2009-01-16 01:54:18]
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.