Restrictions on characters in POST variable names

base64, php, post

Solution

The following characters not allowed in variable names:

chr(32) ( ) (space)
chr(46) (.) (dot)
chr(91) ([) (open square bracket)
chr(128) - chr(159) (various)

(Cite: Get PHP to stop replacing '.' characters in $_GET or $_POST arrays?)

For the other guys, `+, /, and =` are fine for `$_POST`, and for variable names.

First, if you are sure all the underscores in `$_POST` should be periods (which may or may not be a fair assumption, but...)

<form name=test>
<input type=text name="+./=" value='hello'>
<input type=submit>

<?php
foreach ($_POST as $key=>$postVar)
{
$newKey=str_replace("_",".",$key);
$newPost[$newKey]=$postVar;
}
$_POST=$newPost;
echo $_POST['+./=']; //hello

and in variable names, you can use Variable variables

${'var+./='}=1;
echo ++${'var+./='}; //2
?>

Problem

I was recently surprised to learn that PHP will automagically and unpreventably turn all periods to underscores in the names of POST fields, because periods are not allowed in variable names in PHP. I have POST data that is keyed with names that have arbitrary data in them, and I was thinking about Base64 encoding the POST names to avoid the period problem. However, the Base64 alphabet includes the characters `+`, `/` and `=`. These letters are also not allowed in variable names, but are these alright for POST names? What will PHP do with them?

Original source

Related problems