PHP的filter_input()在外部主机上剥离$ _SERVER数据,但在本地主机上工作 [英] PHP's filter_input() strips $_SERVER data on external host, but works on localhost

查看:89
本文介绍了PHP的filter_input()在外部主机上剥离$ _SERVER数据,但在本地主机上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行apache2服务器,在该服务器上进行本地主机测试(PHP 5.5),但是我的托管服务提供商提供了PHP 5.3.我不知道这是否是一个问题,但我以防万一.

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.

我的问题是这样的: 我试图注意几个$ _SERVER变量,但是filter_input()函数由于某种原因返回false,但仅在我的主机服务器上.在localhost上可以正常工作.

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.

回显验证预期的输出:

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

返回预期:

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');

以上所有内容在托管服务提供商上执行时均返回一个空字符串/FALSE,但在我的本地主机上按预期工作.

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.

推荐答案

我遇到了同样的问题,我无法告诉您为什么它返回空字符串/FALSE,但是对我来说,它使用的是INPUT_ENV而不是INPUT_SERVER正常工作,并返回与$_SERVER['REMOTE_ADDR']相同的IP地址. HTTP_USER_AGENT也是如此.简短示例:

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);

这篇关于PHP的filter_input()在外部主机上剥离$ _SERVER数据,但在本地主机上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆