[英]$_SERVER['REQUEST_METHOD'] return GET insted POST
I create a form using post method like that:我使用这样的 post 方法创建了一个表单:
<form name="indexFormn" id="indexForm" method="POST" action="page.php">
<div class="AdminformDiv">
<div class="errorbox">
<?php
if (!is_array($this->actionErrors)) {
echo $this->actionErrors;
}
?>
</div>
<div>
<table border="0" cellpadding="0" cellspacing="0" style="width:700px">
<tbody>
<tr>
<td style="width:128px">Amount</td>
<td colspan="2">$ <?php echo $this->price;?> USD<td style="width:270px"> </td>
</tr>
<tr>
.....
but the problem is when I do "var_dump($_SERVER['REQUEST_METHOD']);"但问题是当我执行“var_dump($_SERVER['REQUEST_METHOD']);” in my php code I get all time "GET" not "POST" and really I don't know why?在我的 php 代码中,我总是得到“GET”而不是“POST”,我真的不知道为什么?
Basically most HTTP requests are GET requests. 基本上大多数HTTP请求都是GET请求。 and $_SERVER['REQUEST_METHOD'] evaluates default GET method. 和$ _SERVER ['REQUEST_METHOD']计算默认的GET方法。
you can use if($_POST) to check if it's a POST. 您可以使用if($ _ POST)来检查它是否是POST。 (That's the array with POST data in it. All pages have $_GET set, so if($_GET) won't work to tell if it's a GET) (这是包含POST数据的数组。所有页面都设置了$ _GET,所以如果($ _ GET)无法判断它是否为GET)
when you submit your form then you will sure get POST method on "page.php". 当您提交表单时,您肯定会在“page.php”上获得POST方法。 try to get method on this page and found. 尝试在此页面上找到方法并找到。
I just had this problem using Codeigniter's MVC Framework. 我刚使用Codeigniter的MVC框架遇到了这个问题。 Here's what I discovered: 这是我发现的:
My Action attribute in my form did not include the "www" in front of my domain, but my actual URL needed the "www". 我的表单中的我的Action属性在我的域前面没有包含“www”,但我的实际URL需要“www”。
ie my form had action="https://mydomain/something"
but if I went to that URL, I noticed my web host added the www to the beginning: https://www.mydomain/something
. 即我的表单有action="https://mydomain/something"
但如果我去了那个URL,我注意到我的网站主持人在开头添加了www: https://www.mydomain/something
。 (I use DreamHost and it's a setting that I had picked) (我使用的是DreamHost,这是我选择的设置)
I hope this is your issue as well - really frustrating to try and figure out, but once I got my action and actual URL to agree on the "www", my request method went from GET to POST. 我希望这也是你的问题 - 尝试弄清楚真的很令人沮丧,但是一旦我得到我的行动和实际的URL以同意“www”,我的请求方法就从GET变为POST。
Following on the answer by @Brian Stork, it is because of some sort of redirection that happens.按照@Brian Stork 的回答,这是因为发生了某种重定向。 The redirection can be because of the following:重定向可能是由于以下原因:
certbot
activates this if you want.例如,如果需要, certbot
激活它。 You can change this in your .conf
file and then systemctl restart apache2
您可以在.conf
文件中更改它,然后systemctl restart apache2
www
subdomain redirection www
子域重定向So check for all these.所以检查所有这些。 And if you are doing a bot like a Slack bot that sends requests to your app, check what is the exact url they are sending to avoid redirection.如果你正在做一个像 Slack 机器人这样的机器人向你的应用程序发送请求,请检查他们发送的确切 url 是什么以避免重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.