PHP $ _POST array variables truncated

I am using PHP 5.3.8 with Apache 2.0. I also use Symfony 2, but not where the script does not work. I have a form with array variables:

<form action="/app_dev.php/admin/position/create" method="post"> <input type="text" id="po_name" name="po[name]" required="required" maxlength="50"> <input type="text" id="po_role" name="po[role]" required="required" maxlength="20"> </form> 

Directly in the app_dev.php file (to exclude symfony from the problem):

 echo file_get_contents("php://input"); // outputs: po%5Bname%5D=Developer&po%5Brole%5D=ROLE_USER var_dump($_POST); // outputs: array(1) { ["po"]=> array(1) { ["name"]=> string(9) "Developer" } } die(); 

Basically, it only saves the first variable in the array. If I change the variable name from po [role] to ba [role], then $ _POST is returned:

 array(1) { ["po"]=> array(1) { ["name"]=> string(9) "Developer" }, ["ba"]=> array(1) { ["role"]=> string(9) "ROLE_USER" } } 

The typical problems that I discovered can cause this problem due to the following php.ini configuration, I also give you what are my values:

 max_execution_time = 30 max_input_time = 60 max_input_nesting_level = 64 max_input_vars = 1000 post_max_size = 8M upload_max_filesize = 2M memory_limit = 128M 

These values ​​seem reasonable, and I think this does not cause a problem, but cannot be 100% sure.

I do not have suhosin installed as I read it, it can cause similar problems.

It also looks like this problem , but for this solution I will need to rewrite the HttpFoundation Symfony component.

In addition, I do not want to rewrite the form variable without and array (for example, po [name] in po_name), since the form is automatically generated by Symfony, and this, apparently, is the main feature with which PHP should be able to handle.

Does anyone have any ideas on this issue?

PS: this is similar to the problem described here . Plus, the problem occurs in the same version of Suse (SUSE Linux Enterprise Server 11).

+6
source share
2 answers

Finally, we decided to upgrade our version of PHP to a later version (5.3.15), and now it works fine. So that was the problem with this 5.3.8, at least we had a version.

+1
source

What you offer works great for me. Full test code:

 <html> <body> <pre> <?php if (isset($_POST) && !empty($_POST)) { echo file_get_contents("php://input"); echo "\n\n"; var_dump($_POST); } ?> </pre> <form action="" method="post"> <input type="text" id="po_name" name="po[name]"> <input type="text" id="po_role" name="po[role]"> <input type="submit"> </form> </html> 

Summary of results with the values ​​one and two:

 po%5Bname%5D=one&po%5Brole%5D=two array(1) { ["po"]=> array(2) { ["name"]=> string(3) "one" ["role"]=> string(3) "two" } } 

My PHP:

 PHP Version 5.3.3-7+squeeze14 CGI/FastCGI Apache/2.2 Suhosin Patch 0.9.9.1 

There are no problems, so it should work clearly. If this test code does not work for you, the best option is a PHP error in your version (or an error in some seemingly unrelated functions that were not mentioned anywhere).

+1
source

Source: https://habr.com/ru/post/926723/


All Articles