Despite the documentation for 'type', you can specify multiple types by doing:
$test = filter_input(INPUT_GET | INPUT_POST, 'test');
This was tested in 5.2.3.
When both are set it appears to return the value defined first by variables_order (php.ini).
This trick does not seem to work in filter_input_array though. Neither function supports INPUT_REQUEST at the moment.
filter_input
(PHP 5 >= 5.2.0, PECL filter:0.11.0)
filter_input — Obtiene una variable desde afuera de PHP y opcionalmente la filtra
Descripción
Lista de parámetros
- tipo
-
Un valor entre INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, INPUT_ENV, INPUT_SESSION (aun no implementado) y INPUT_REQUEST (aun no implementado).
- nombre_variable
-
Nombre de una variable a obtener.
- filtro
-
Filtro a aplicar. Su valor predeterminado es FILTER_DEFAULT.
- opciones
-
Matriz asociativa de opciones o disyunción a nivel de bits de banderas. Si el filtro acepta opciones, las banderas pueden definirse en el campo "flags" de la matriz.
Valores retornados
El valor de la variable solicitada en caso de éxito, FALSE si el filtro falla, o NULL si la variable nombre_variable no está definida. Si la bandera FILTER_NULL_ON_FAILURE es usada, se devuelve FALSE si la variable no está definida y NULL si el filtro falla.
Ejemplos
Example #1 Un ejemplo de filter_input()
<?php
$html_busqueda = filter_input(INPUT_GET, 'busqueda', FILTER_SANITIZE_SPECIAL_CHARS);
$url_busqueda = filter_input(INPUT_GET, 'busqueda', FILTER_SANITIZE_ENCODED);
echo "Ha realizado una búsqueda por $html_busqueda.\n";
echo "<a href='?buscar=$url_busqueda'>Buscar de nuevo.</a>";
?>
El resultado del ejemplo seria algo similar a:
Ha realizado una búsqueda por Me & son. <a href='?buscar=Me%20%26%20son'>Buscar de nuevo.</a>
filter_input
02-Jan-2008 08:30
10-Dec-2007 09:49
If you want to use the callback filter with filter_input, you need to do something like:
$args = array ('options' => 'mycallbackfunction');
$foobar = filter_input(INPUT_POST,'postedvariable',FILTER_CALLBACK,$args);
23-Aug-2007 11:10
FastCGI seems to cause strange side-effects with unexpected null values when using INPUT_SERVER and INPUT_ENV with this function. You can use this code to see if it affects your server:
<?php
var_dump($_SERVER);
foreach ( array_keys($_SERVER) as $b ) {
var_dump($b, filter_input(INPUT_SERVER, $b));
}
echo '<hr>';
var_dump($_ENV);
foreach ( array_keys($_ENV) as $b ) {
var_dump($b, filter_input(INPUT_ENV, $b));
}
?>
If you want to be on the safe side, using the superglobal $_SERVER and $_ENV variables will always work. You can still use the filter_* functions for Get/Post/Cookie without a problem, which is the important part!
