[英]Why is $_SERVER['REQUEST_METHOD'] always 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>
Note: this page lives at /page
and is echoed after the following HTML: 注意:此页面位于
/page
并在以下HTML之后回显:
On /page
I have this at the very top of the file: 在
/page
我在文件的最顶部有这个:
<?php
var_dump($_SERVER['REQUEST_METHOD']);
For some reason, it always shows up as GET
when I submit this form. 出于某种原因,当我提交此表单时,它总是显示为
GET
。 If I take the action="/page"
part out then it shows up as POST
. 如果我将
action="/page"
部分取出,那么它会显示为POST
。 What am I missing here? 我在这里错过了什么?
Note: Even when I load the page, then put at exit after the above var_dump()
call, it still shows GET
. 注意:即使我加载页面,然后在上面的
var_dump()
调用之后退出,它仍然显示GET
。
In the inspector's timeline I see this for the request: 在检查员的时间表中,我看到了这个请求:
Thanks to the comments to my question I have found the answer to be in apache configuration. 感谢对我的问题的评论,我发现答案是在apache配置中。 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. 看起来,因为
index.php
文件位于名为page
的文件夹中,所以apache会自动重定向到带有斜杠的页面。 This is the default setting as seen in the Apache directorySlash documentation . 这是Apache directorySlash文档中的默认设置。
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.\\ 或者,当然,我可以使用适当的重写规则设置添加
.htaccess
文件。
Thanks for everyone's help! 谢谢大家的帮助! As a side note, Safari's inspector left me a little wanting in this case.
作为旁注,Safari的检查员在这种情况下让我有点想要。 Chrome turned out to be a far better option for testing.
Chrome被证明是一个更好的测试选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.