当 GET 和 POST 发送相同的值时,$_REQUEST 会 return 做什么?
what $_REQUEST will return when same values sent by GET and POST?
我正在尝试在 PHP
中创建一个表单,我使用用户 ID 通过 GET 在表单中显示数据,但是在 POST 提交表单后,我将用户 ID 存储在隐藏字段中。 .
在尝试这个过程中,我对 GET
、POST
和 REQUEST
感到困惑。
看到这个情况
<form action="script.php?id=777" method="post">
ID: <input type="text" name="id" />
<input type="submit" value="Send" />
</form>
假设我在文本字段中输入“888”
何时提交此表单,$_REQUEST['id'];
应提供什么值?
全部都一样php versions
?
如果我将文本字段留空会怎样?
如果我将操作更改为 action="script.php?id="
会发生什么?
01
如果表单在post
方法中
<form action="script.php" method="post">
ID: <input type="text" name="id" />
<input type="submit" value="Send" />
</form>
在script.php
中,可以使用
获取数据
$id = $_POST['id'];//works
$id = $_REQUEST['id'];//works
$id = $_GET['id'];//Failed
02
如果表单在get
方法中
<form action="script.php" method="get">
ID: <input type="text" name="id" />
<input type="submit" value="Send" />
</form>
在script.php
中,可以使用
获取数据
$id = $_GET['id'];//works
$id = $_REQUEST['id'];//works
$id = $_POST['id'];//Failed
可以参考$_REQUEST vs $_GET and $_POST and What's wrong with using $_REQUEST[]?
实际顺序由PHP.ini文件中的"request_order"设置决定
; This directive determines which super global data (G,P,C,E & S) should
; be registered into the super global array REQUEST. If so, it also determines
; the order in which that data is registered. The values for this directive are
; specified in the same manner as the variables_order directive, EXCEPT one.
; Leaving this value empty will cause PHP to use the value set in the
; variables_order directive. It does not mean it will leave the super globals
; array REQUEST empty.
; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order = "GP"
通常默认设置为Get then Post。在这种情况下,您将 id 参数作为 get AND 作为 post 参数提供。这意味着 $_REQUEST 首先被 $_GET 填充,然后是 $_POST。意味着 $_REQUEST 将反映 $_POST。
我正在尝试在 PHP
中创建一个表单,我使用用户 ID 通过 GET 在表单中显示数据,但是在 POST 提交表单后,我将用户 ID 存储在隐藏字段中。 .
在尝试这个过程中,我对 GET
、POST
和 REQUEST
感到困惑。
看到这个情况
<form action="script.php?id=777" method="post">
ID: <input type="text" name="id" />
<input type="submit" value="Send" />
</form>
假设我在文本字段中输入“888”
何时提交此表单,$_REQUEST['id'];
应提供什么值?
全部都一样php versions
?
如果我将文本字段留空会怎样?
如果我将操作更改为 action="script.php?id="
会发生什么?
01
如果表单在post
方法中
<form action="script.php" method="post">
ID: <input type="text" name="id" />
<input type="submit" value="Send" />
</form>
在script.php
中,可以使用
$id = $_POST['id'];//works
$id = $_REQUEST['id'];//works
$id = $_GET['id'];//Failed
02
如果表单在get
方法中
<form action="script.php" method="get">
ID: <input type="text" name="id" />
<input type="submit" value="Send" />
</form>
在script.php
中,可以使用
$id = $_GET['id'];//works
$id = $_REQUEST['id'];//works
$id = $_POST['id'];//Failed
可以参考$_REQUEST vs $_GET and $_POST and What's wrong with using $_REQUEST[]?
实际顺序由PHP.ini文件中的"request_order"设置决定
; This directive determines which super global data (G,P,C,E & S) should
; be registered into the super global array REQUEST. If so, it also determines
; the order in which that data is registered. The values for this directive are
; specified in the same manner as the variables_order directive, EXCEPT one.
; Leaving this value empty will cause PHP to use the value set in the
; variables_order directive. It does not mean it will leave the super globals
; array REQUEST empty.
; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order = "GP"
通常默认设置为Get then Post。在这种情况下,您将 id 参数作为 get AND 作为 post 参数提供。这意味着 $_REQUEST 首先被 $_GET 填充,然后是 $_POST。意味着 $_REQUEST 将反映 $_POST。