$ _SERVER ['REQUEST_METHOD']返回GET insted POST

Jea*_*Ter 5 php post get

我使用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">&nbsp;</td>
            </tr>
            <tr>

.....
Run Code Online (Sandbox Code Playgroud)

但问题是当我做"var_dump($ _ SERVER ['REQUEST_METHOD']);" 在我的PHP代码中我得到的所有时间"GET"而不是"POST",我真的不知道为什么?

Rak*_*rma 1

基本上大多数 HTTP 请求都是 GET 请求。$_SERVER['REQUEST_METHOD'] 评估默认的 GET 方法。

您可以使用 if($_POST) 来检查它是否是 POST。(这是包含 POST 数据的数组。所有页面都设置了 $_GET,因此 if($_GET) 无法判断它是否是 GET)

当您提交表单时,您一定会在“page.php”上获得 POST 方法。尝试在此页面上获取方法并找到。