为什么$ _SERVER ['REQUEST_METHOD']总是GET? [英] Why is $_SERVER['REQUEST_METHOD'] always GET?

查看:744
本文介绍了为什么$ _SERVER ['REQUEST_METHOD']总是GET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此有点困惑。我希望这是我错过的非常明显的事情!我有一个非常简单的表单:

I'm a bit confused about this. I'm hoping it's something wildly obvious I've missed! I have a very simple form:

<form class="form-signin" role="form" name="login" method="POST" action="/page">
  <input type="password" name="password" />
  <input type="submit" value="Sign in" />
</form>

注意:此页面位于 /页面并在下面的HTML之后被回显:

Note: this page lives at /page and is echoed after the following HTML:

/ page 该文件的最顶端:

On /page I have this at the very top of the file:

<?php
var_dump($_SERVER['REQUEST_METHOD']);

由于某些原因,始终显示为 GET 提交此表单时。如果我将 action =/ page部分取出,它会显示为 POST 。我在这里错过了什么?

For some reason, it always shows up as GET when I submit this form. If I take the action="/page" part out then it shows up as POST. What am I missing here?

注意:即使当我加载页面,然后在上面的 var_dump()调用,它仍然显示 GET

Note: Even when I load the page, then put at exit after the above var_dump() call, it still shows GET.

在督察的时间表I看到这个请求:

In the inspector's timeline I see this for the request:

推荐答案

感谢对我的问题的评论,我发现答案是在Apache配置中。看起来,因为 index.php 文件位于名为 page 的文件夹内,所以apache会自动重定向到页面斜杠上。这是默认设置,如Apache directorySlash文档所示。

Thanks to the comments to my question I have found the answer to be in apache configuration. It appears that, because the index.php file is inside a folder called page, apache will automatically redirect to the page with a slash on it. This is the default setting as seen in the Apache directorySlash documentation.

当他们警告不要关闭此功能时,我会将网址更改为我要发布的内容。或者,当然,我可以添加一个 .htaccess 文件,并设置适当的重写规则。\

As they warn against turning this off, I will just change the url to what I'm posting. Alternatively, of course, I could add a .htaccess file with proper rewrite rules setup.\

感谢大家的帮助!作为一个侧面说明,Safari的检查员在这种情况下让我有点想要。 Chrome原来是一个更好的测试选项。

Thanks for everyone's help! As a side note, Safari's inspector left me a little wanting in this case. Chrome turned out to be a far better option for testing.

这篇关于为什么$ _SERVER ['REQUEST_METHOD']总是GET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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