0

Today I came across the strange behaviour with PHP _POST array. When submitting form fields named as multidimensional array PHP supports, the POST is filled with only the first value from array. Found this on PHP 5.3.8 (SLES 11 SP2). The same code works normally on all other systems I have access to including PHP 5.2, 5.3.18, and 5.4. Here is a test case:

<form method="POST" action="test.php">
<input type="text" name="single" value="sss"/><br>
<input type="text" name="multi[a]" value="AAA"/><br>
<input type="text" name="multi[b]" value="BBB"/><br>
<input type="text" name="single2" value="CCC"/><br>
<input type="submit">
</form>
<?php
$raw_post = file_get_contents('php://input');
print $raw_post;
phpinfo(INFO_VARIABLES);

After submitting this I get the following in raw data:

single=sss&multi%5Ba%5D=AAA&multi%5Bb%5D=BBB&single2=CCC

But $_POST array is filled only with first value from "multi", $_POST['multi'] provides:

Array
(
    [a] => AAA
)

Does anybody know why this can happen?

  • 1
    does this happen often when you test this code? I tried your code and it seems to var_dump($_POST['multi']) correctly. It shows an array containing 'a' and 'b' – Ren Camp Mar 17 '16 at 14:15
  • The result is the same every time :( Stuck with this issue for two days, can't imagine why this happens ... – Dead Mazzay Mar 17 '16 at 14:40
  • I modified the printing of your code a little here: https://preview.c9users.io/reneecampanilla/sof-36062907 and you can test it here: https://sof-36062907-reneecampanilla.c9users.io – Ren Camp Mar 17 '16 at 15:00
  • Thanks Ren, I see its working on your server. It also works on my other servers but not on 5.3.8. I found another user complained about the same issue and his solution was to update PHP. http://stackoverflow.com/questions/12684449/php-post-array-variables-are-truncated?rq=1 – Dead Mazzay Mar 17 '16 at 15:58
  • Upgrading/updating is a good idea. Good luck with your programming! – Ren Camp Mar 17 '16 at 23:27

0 Answers0