- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么此行在我的实时服务器中返回 null
?
filter_input(INPUT_SERVER, 'REQUEST_METHOD');
实时服务器是php5.5.9
我错过了什么吗?
我以为是用来替换下面的全局方法的?
$_SERVER['REQUEST_METHOD'];
一些代码,
public function __construct()
{
// Construct other generic data.
$this->clientRequestMethod = filter_input(INPUT_GET, 'method'); // such as list, add, update, etc
$this->clientPostMethod = filter_input(INPUT_POST, 'method'); // such as update
$this->serverRequestMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD'); //such as get or post
}
public function processEntry()
{
// Determine the $_SERVER['REQUEST_METHOD'] whether it is post or get.
if ($this->serverRequestMethod === 'POST' && $this->clientPostMethod != null)
{
$this->processPost();
}
else if($this->serverRequestMethod === 'GET' && $this->clientRequestMethod != null)
{
$this->processRequest();
}
}
最佳答案
所以问题/错误是这样的:
当您使用 FASTCGI 时,filter_input() 无法与 INPUT_SERVER 或 INPUT_ENV 一起使用
这个错误已经存在很多年了,但我没有发现任何消息表明它已得到解决。我找到了几种解决方法,但没有完整的解决方案,因此我将最佳的解决方法放入此帮助函数中,以实现项目范围的解决方案。为了提供一定程度的安全性并避免火车失事,该函数回退到filter_var(),其中filter_input() 失败。它使用与 native filter_input() 函数相同的格式,以便轻松集成到项目中,并在错误修复后轻松删除。
function filter_input_fix ($type, $variable_name, $filter = FILTER_DEFAULT, $options = NULL )
{
$checkTypes =[
INPUT_GET,
INPUT_POST,
INPUT_COOKIE
];
if ($options === NULL) {
// No idea if this should be here or not
// Maybe someone could let me know if this should be removed?
$options = FILTER_NULL_ON_FAILURE;
}
if (in_array($type, $checkTypes) || filter_has_var($type, $variable_name)) {
return filter_input($type, $variable_name, $filter, $options);
} else if ($type == INPUT_SERVER && isset($_SERVER[$variable_name])) {
return filter_var($_SERVER[$variable_name], $filter, $options);
} else if ($type == INPUT_ENV && isset($_ENV[$variable_name])) {
return filter_var($_ENV[$variable_name], $filter, $options);
} else {
return NULL;
}
}
这似乎是最好的解决方案。如果它包含可能导致问题的错误,请告诉我。
关于PHP filter_input(INPUT_SERVER, 'REQUEST_METHOD' ) 返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25232975/
我刚刚安装了 WAMP,我可以访问本地主机并获取 phpinfo() 输出。 但是,虽然我可以看到 _SERVER['REQUEST_METHOD'] 设置为 GET,但我正在尝试使用以下 PHP:
我的代码中目前有 strtoupper($_SERVER['REQUEST_METHOD'])。 但是 strtoupper 调用有必要吗? $_SERVER['REQUEST_METHOD'] 是否
在我正在开发的 PHP 项目中,我有几个可以是 POST 或 GET 的请求。目前,我使用 $_SERVER[REQUEST_METHOD] 值来确定要使用哪个请求数组。我知道 $_REQUEST 值
所以,一段时间以来,我一直在使用以下方法检查我的帖子数据是否已设置。 if( ! empty( $_POST ) ) { } 但最近我看到很多帖子说上面是“hack”而下面是正确的“更好”方式。 if
我有一个包含 2 个表单的页面。这是为了使用 PHP/PDO 插入数据库。我面临的问题是,即使我没有按下提交按钮,插入页面上的 IF 语句也会产生错误。已尝试使用 $_POST isset/!==0
一直在对此进行一些挖掘,但是找不到信息 我正在尝试检查表单是否已提交以及它是 GET 还是 POST。所以基本上我使用: if($_SERVER['REQUEST_METHOD'] == 'GET')
我正在为我的本地开发站点使用 nginx + php5-fpm。在构建表单时,我遇到了一个非常奇怪的问题。 似乎 $_SERVER['REQUEST_METHOD'] 在我发布时有时会被误报为“GET
在实际使用 $_SERVER['REQUEST_METHOD'] 之前,我是否必须检查 $_SERVER 变量是否具有键 REQUEST_METHOD? 也就是说,总是检查数组变量中是否存在某个键是否
这个问题在这里已经有了答案: $_POST vs. $_SERVER['REQUEST_METHOD'] == 'POST' (11 个答案) 关闭 8 年前。 我在看一个关于PHP表单提交的视频,
我在这里搜索了大约十几个与以下内容相关的答案: if ($_SERVER['REQUEST_METHOD'] == 'POST') { } 但我仍然没有找到原因的答案。为什么。 如果我们已经设置了,为
为什么此行在我的实时服务器中返回 null? filter_input(INPUT_SERVER, 'REQUEST_METHOD'); 实时服务器是php5.5.9 我错过了什么吗? 我以为是用来替
我有以下代码,每当我尝试插入数据时,$content 都没有被插入,问题可能出在哪里?我正在使用功能测试输入来解决安全相关问题。 Article Published"; echo" View it N
对 php 有点陌生,阅读了一些人的代码,看到了这个: if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['.
我在 login.php 中得到了这段代码: login.php Log in: Username: Password: 我是一个 php 初学者,我正在尝试将数据发布
我遇到了最奇怪的问题,我不知道如何解决。我的表格第一行是: 但是当我回显 $_SERVER['REQUEST_METHOD'] 时,它会回显“GET”。我正在使用 CodeIgniter,所以我不知
我对此有点困惑。我希望这是我错过的非常明显的事情!我有一个非常简单的表格: 注意此页面位于 /page 并在以下 HTML 之后回显: 在 /page 上,我在文件的最顶部有这个: <
有人称我的 Snipplr 提交之一“垃圾”,因为我使用 if ($_SERVER['REQUEST_METHOD'] == 'POST') 而不是 if ($_POST) 检查请求方法对我来说似乎更
我的问题与this one 非常相似但我不明白为什么我的请求会是跨域的。这是我用 Firebug 得到的结果: 所有域都一样,我不明白为什么 Firefox 和 IE 有这种行为。 你可以测试here
" method="POST"> Admin Login 我在php上制作了method="POST"表单 if ($_SERVER['REQUEST_ME
我正在使用 C 处理一个 CGI 文件,该文件仅在请求方法为 POST 时才执行操作。 int main(void) { char *method_str = getenv("REQUE
我是一名优秀的程序员,十分优秀!