Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP's filter_input() strips $_SERVER data on external host, but works on localhost

I am running an apache2 server where I do my localhost testing (PHP 5.5), but my hosting provider has PHP 5.3. I don't know whether that is an issue, but I mention it just in case.

My problem is this: I am seeking to note a couple of $_SERVER variables, but the filter_input() function returns false for some reason, but only on my host server. It works fine on localhost.

Echoing verifies the expected output:

echo $_SERVER['HTTP_USER_AGENT'];
echo $_SERVER['REMOTE_ADDR'];

Returns as expected:

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36
90.10.160.140    (Not the actual address)

But when I use the filter (even without a filter/options specified!), both are blank:

filter_input(INPUT_SERVER,'HTTP_USER_AGENT',FILTER_SANITIZE_ENCODED,FILTER_FLAG_STRIP_LOW);
filter_input(INPUT_SERVER,'REMOTE_ADDR',FILTER_VALIDATE_IP);
filter_input(INPUT_SERVER,'HTTP_USER_AGENT');
filter_input(INPUT_SERVER,'REMOTE_ADDR');

All of the above return an empty string/FALSE when executed on my hosting provider, yet work as expected on my localhost.

I'm guessing there is some config parameter set differently on the host. Any idea which one? Or what else might be the matter? Thanks.

like image 248
rayvd Avatar asked Mar 19 '23 17:03

rayvd


2 Answers

I had the same problem, I won't be able to tell you why it returns an empty string/FALSE but for me using INPUT_ENV instead of INPUT_SERVER did work and returns the same IP-address as $_SERVER['REMOTE_ADDR']. Same goes for HTTP_USER_AGENT. Short example:

$REMOTE_ADDR = filter_input(INPUT_ENV, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
like image 128
Marco de Zeeuw Avatar answered Apr 07 '23 23:04

Marco de Zeeuw


My guess would be something related to this bug: https://github.com/wp-stream/stream/issues/254

Try to use the bugfix on your code as a workaround

like image 31
jonathanglima Avatar answered Apr 08 '23 00:04

jonathanglima