Tuesday, November 04, 2008

PHP doesn't support dot characters in form names

I've written a PHP proxy script that communicates with an underlying application. I encountered a problem where the script is unable to proxy data that contains dot characters in the form name.

To illustrate:
<?php
var_dump($_POST);
?>
<form action="test.php" method="post">
<input name="this.is.a/variable" type="text" />
<input type="submit" />
</form>
Output:
array(1) {
["this_is_a/variable"]=>
string(0) ""
}
Notice the array key in the var_dump(); dots are converted into underscore.

Solution

I accessed the raw input stream directly instead of using $_POST:
<?php
$data = file_get_contents("php://input");
$response = proxy_blah_blah($data);
?>

No comments: