小编rae*_*kid的帖子

神秘的空 $_POST 数组

我有以下 HTML/PHP 页面:

<?php
if(empty($_SERVER['CONTENT_TYPE'])) {
    $type = "application/x-www-form-urlencoded";
    $_SERVER['CONTENT_TYPE'] = $type;
}

echo "<pre>";
var_dump($_POST);
var_dump(file_get_contents("php://input"));
echo "</pre>";
?>

<form method="post" action="test.php">
<input type="text" name="test[1]" />
<input type="text" name="test[2]" />
<input type="text" name="test[3]" />
<input type="submit" name="action" value="Go" />
</form>
Run Code Online (Sandbox Code Playgroud)

如您所见,表单将提交并且预期的输出是一个 POST 数组,其中一个数组包含填充的值和一个值为“Go”(按钮)的条目“action”。但是,无论我在字段中输入什么值;结果总是:

array(2) {
  ["test"]=>
  string(0) ""
  ["action"]=>
  string(2) "Go"
}
string(16) "test=&action=Go&"
Run Code Online (Sandbox Code Playgroud)

不知何故,名为 test 的数组被清空,“action”变量确实通过了。

我已经使用了 Firefox 的 Live HTTP Headers 扩展来检查 POST 字段是否被提交,他们确实提交了。来自 Live HTTP Headers 的相关信息(在文本框中填充了 a、b 和 c 作为值):

Content-Type: application/x-www-form-urlencoded
Content-Length: 51
test%5B1%5D=a&test%5B2%5D=b&test%5B3%5D=c&action=Go …
Run Code Online (Sandbox Code Playgroud)

php

22
推荐指数
1
解决办法
7万
查看次数

标签 统计

php ×1