Discussion:
$_SERVER vs filter_input_array(INPUT_SERVER)
(too old to reply)
Jakub
2024-04-09 10:55:21 UTC
Permalink
Welcome

I have this script

<?php

$a = $_SERVER;

foreach ( $a as $k => $v) {
echo $k . ' => ' . $v . '<br>';
}

echo '<hr><br>';

$b = filter_input_array(INPUT_SERVER);

foreach ( $b as $k => $v) {
echo $k . ' => ' . $v . '<br>';
}

The result is almost the same.

But $_SERVER give to access to this keys:

REQUEST_TIME_FLOAT and REQUEST_TIME

but filter_input_array(INPUT_SERVER)
don't have these keys.

How to fix this problem?
J.O. Aho
2024-04-09 11:54:02 UTC
Permalink
Post by Jakub
The result is almost the same.
REQUEST_TIME_FLOAT and REQUEST_TIME
but filter_input_array(INPUT_SERVER)
don't have these keys.
If I haven't understood things wrong, the source data the both have is
the same, but there are some values which are added on at a bit later
stage to $_SERVER and $_ENV which makes some of the values to not exists
in the filter_input_array(INPUT_SERVER)/filter_input_array(INPUT_ENV).
Post by Jakub
How to fix this problem?
You take them from $_SERVER

You can also still filter the values:
var_export(filter_var($_SERVER['REQUEST_TIME'], FILTER_VALIDATE_INT));

var_export(filter_var($_SERVER['REQUEST_TIME_FLOAT'],
FILTER_VALIDATE_FLOAT));
--
//Aho
Loading...