I got weird results when I try to use filter_input
with INPUT_SERVER
(I am using PHP 5.6.9).
I run this code:
var_dump($_SERVER);
foreach (array_keys($_SERVER) as $varkey) {
var_dump($varkey, filter_input(INPUT_SERVER, $varkey));
}
I get that every filter_input(INPUT_SERVER, $varkey)
returns null. But $_SERVER
have correct values.
Why that's happening?
This is a known PHP bug. Try this:
$result = filter_input(INPUT_SERVER, 'SERVER_NAME');
/*
* overcome bug filter_input some php versions would return null
* on some implementations of FCGI/PHP 5.4 and probably older
* versions as well.
*
* https://bugs.php.net/bug.php?id=49184
*/
if (empty($result) && isset($_SERVER['SERVER_NAME'])) {
$result = Filter::sanitize($_SERVER['SERVER_NAME'], $filter);
}
This my wrapper until they fix this situation. Until then it must deal with it.