Search code examples
phpfilter-input

PHP filter_input REQUEST_TIME


filter_input(INPUT_SERVER, 'REQUEST_TIME') returns nothing.

as opposed to directly accessing $_SERVER['REQUEST_TIME'], which returns proper number.

Am I doing something wrong? HTTP_USER_AGENT for example is returned ok.

I searched for it and didn't find any, seems like REQUEST_TIME is not accessible through filter_input for some reason.

Tested on PHP 5.6 and 7.0.


Solution

  • Don't quote me, but something like this is your problem. REQUEST_TIME is added to $_SERVER after the HTTP REQUEST is processed by your web server (or, more accurately, by the PHP module). It does not appear in the HTTP headers/query string, blah, blah, blah, so you cannot filter REQUEST_TIME like you can HTTP_HOST, HTTP_USER_AGENT, REQUEST_URI, or USER_IP. I use the PHP filter functions, too. To verify my pseudo-answer, use ...

    if(filter_has_var(INPUT_SERVER, 'REQUEST_TIME'))
    {
         echo 'REQUEST_TIME is filterable with filter_input()';
    }
    else
    { 
         echo 'TOUGH LUCK';  //Kidding.
    }
    

    I just tested this on PHP 5.6.11. I feel that I am correct. The code responded 'TOUGH LUCK'. So, similar to SERVER_NAME, REQUEST_TIME is an internal value. The difference being that SERVER_NAME is present during the "magic time." REQUEST_TIME is added afterward. Go figure.