Mysteriously empty $_POST array
- by Lex
Hi all!
I have the following HTML/PHP page:
<?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>
As you can see, the form will submit and the expected output is a POST array with one array in it containing the filled in values and one entry "action" with the value "Go" (the button). However, no matter what values I enter in the fields; the result is always:
array(2) {
["test"]=>
string(0) ""
["action"]=>
string(2) "Go"
}
string(16) "test=&action=Go&"
Somehow, the array named test is emptied, the "action" variable does make it through.
I've used the Live HTTP Headers extension for Firefox to check whether the POST fields get submitted, and they do. The relevant information from Live HTTP Headers (with a, b and c filled in as values in the textboxes):
Content-Type: application/x-www-form-urlencoded
Content-Length: 51
test%5B1%5D=a&test%5B2%5D=b&test%5B3%5D=c&action=Go
Does anybody have any idea as to why this is happening? I'm freaking out on this one, it has cost me so much time already...