本文介绍了$ _SERVER ['REQUEST_METHOD']返回GET insted POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form name =indexFormnid =indexForm method =POSTaction =page.php> 
< div class =AdminformDiv>
< div class =errorbox>
<?php
if(!is_array($ this-> actionErrors)){
echo $ this-> actionErrors;
}
?>
< / div>
< div>
< tbody>
< tr>
< td style =width:128px>金额< / td>
< td colspan =2> $<?php echo $ this-> price;?> USD< td style =width:270px>& nbsp;< / td>
< / tr>
< tr>

.....

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

解决方案

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



您可以使用if($ _ POST)来检查它是否为POST。 (这是带有POST数据的数组,所有页面都有$ _GET集合,所以如果($ _ GET)不能用来判断它是否为GET)



when你提交你的表单,那么你一定会在page.php上获得POST方法。
尝试在此页面上找到方法并找到。


I create a form using post method like that :

  <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>

.....

but the problem is when I do "var_dump($_SERVER['REQUEST_METHOD']);" in my php code I get all time "GET" not "POST" and really I don't know why?

解决方案

Basically most HTTP requests are GET requests. and $_SERVER['REQUEST_METHOD'] evaluates default GET method.

you can use if($_POST) to check if it's a 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)

when you submit your form then you will sure get POST method on "page.php".try to get method on this page and found.

这篇关于$ _SERVER ['REQUEST_METHOD']返回GET insted POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:29