Mysteriously empty $_POST array
Posted
by Lex
on Server Fault
See other posts from Server Fault
or by Lex
Published on 2010-03-30T11:19:00Z
Indexed on
2010/03/30
13:53 UTC
Read the original article
Hit count: 397
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...
EDIT: We've tried this on different servers, on Windows boxes it does work, on the Ubuntu server with PHP version 5.2.4 (with Suhosin), it doesn't. It even works on a different server, also with Ubuntu and the same PHP version, also with Suhosin installed.
© Server Fault or respective owner