问题
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.
回答1:
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);
回答2:
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
来源:https://stackoverflow.com/questions/25316085/phps-filter-input-strips-server-data-on-external-host-but-works-on-localho