当GET和POST发送相同的值时,将返回什么$ _REQUEST? - php

我正在尝试在PHP中创建表单,我使用用户ID通过GET在表单中显示数据,但是在通过POST提交表单之后,我将用户ID存储在隐藏字段中。

尝试此操作时,我只是对GETPOSTREQUEST感到困惑。

看到这种情况

<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="会发生什么?

参考方案

实际顺序在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"

通常,默认设置为“获取然后发布”。在这种情况下,您将id参数作为get AND提供作为post参数。这意味着$ _REQUEST首先填充$ _GET,然后填充$ _POST。意思是$ _REQUEST将反映$ _POST。

PHP:获取调用引用的数组名称 - php

假定以下函数并调用:function doSomething( &$someArray ) { // Do something to $someArray } $names=array("John", "Paul", "George", "Ringo"); doSomet…

PHP-MySQL结果转换为JSON - php

我试图了解如何将MySQL结果转换为JSON格式,以便以后可以在Javascript中使用此JSON来构建HTML表。但是我的代码只是产生大量的空值,我还不明白为什么。$result = mysqli_query($con, "SELECT * FROM Customers"); $test = json_encode($result);…

PHP Count数组元素 - php

嗨,有人可以解释为什么这会返回“数组由0个元素组成”。 :$arr = array(1,3,5); $count = count($arr); if ($count = 0) { echo "An array is empty."; } else { echo "An array has $count elements.…

PHP-将日期插入日期时间字段 - php

我已在数据库中使用datetime字段存储日期,使用PHP将“今天的日期”插入该字段的正确方法是什么?干杯, 参考方案 我认为您可以使用php date()函数

PHP:从函数返回值并直接回显它? - php

这可能是一个愚蠢的问题,但是……的PHPfunction get_info() { $something = "test"; return $something; } html<div class="test"><?php echo get_info(); ?></div> 有没有办…