1

Please consider the following simple test suite:

<?php
$data = file_get_contents('php://input');
echo '<pre>';
echo 'raw: <br/>';
print_r($data);
echo '<br/>$_POST: <br/>';
print_r($_POST);
echo '
<form name="form1" method="post" type="application/x-www-form-urlencoded"   action="postTest.php"/>
<input type="text" name="my1[]" value="1" />
<input type="text" name="my1[]" value="2" />
<input type="text" name="my3" value="3 "/>

<input type="submit" />
</form>

This returns on most servers running PHP5+

raw: 
my1%5B%5D=1&my1%5B%5D=2&my3=3+
$_POST: 
Array
(
    [my1] => Array
        (
            [0] => 1
            [1] => 2
        )

    [my3] => 3 
) 

as expected. However on my local system with Ubuntu 12.10, Apache 2.2.22, PHP 5.4.6, locale tr_TR.UTF-8, it will return

raw: 
my1%5B%5D=1&my1%5B%5D=2&my3=3+
$_POST: 
Array
(
    [my3] => 3 
)

where my1 array is vanished. Please note that $_POST['my3'] is still there and I don't experience any other issue with non-array $_POST data and I can still see m1 is there from raw data. This is really strange behaviour. What could generally cause this issue?

torillt
  • 21
  • 2
  • Just an guess (may waste your extra minute), why `+` is coming at the end of the `raw:` data. Can you please remove the space from the `value` of `my3` field name. – MaNKuR May 30 '13 at 10:32

2 Answers2

0

Can you please try the following?

$post = file_get_contents("php://input");
parse_str($post , $output);
print_r($output);

To see if value getting passed to PHP

xelber
  • 4,197
  • 3
  • 25
  • 33
  • It still returns Array ( [my3] => 3 ) – torillt May 28 '13 at 23:55
  • hmmm.. could be something to do with URL Encoding – xelber May 29 '13 at 00:06
  • can you remove type="application/x-www-form-urlencoded" from the form and test? – xelber May 29 '13 at 00:10
  • I did it and still the same. BTW, I also tried it changing the locale to en.US with no success. I have coded a simple workaround using the idea in thread http://stackoverflow.com/questions/5077969/php-some-post-values-missing-but-are-present-in-php-input . I added the functionality to look for brackets and make arrays out of them, and it seems to be working, so I could use it as the last escape, yet I would still want to solve this issue according to the book, not relying on such attractions. – torillt May 29 '13 at 00:22
  • Agree, check the comment on http://php.net/manual/en/function.urlencode.php Mark Seecof – xelber May 29 '13 at 00:25
  • can you try $post = file_get_contents("php://input"); parse_str(urldecode($post) , $output); print_r($output); – xelber May 29 '13 at 02:01
  • I had also tried that, with your hint to dig the encoding, but nothing changed so far. – torillt May 29 '13 at 02:23
  • I am out of options and as far as I can see, this is a PHP bug and I will issue a bug report. Thank you very much for your help so far. I would like to mark your answer as useful, but stackoverflow won't let me do it until I'll have some reputation around here. – torillt May 29 '13 at 03:10
0

A wild guess...

[ and ] are not valid in javascript identifiers neither are they valid in xhtml name attributes.

So two ideas:

One server is serving xhtml and the other html.

You are using different browsers and one is more picky about name attributes than the other.

I think you could turn your fields names into my1_0 and my1_1, or similar.

Ian
  • 1,941
  • 2
  • 20
  • 35
  • I also tried with identical server and client parameters (e.g. with the same version of apache and php versus [chrome,firefox]). I need to get this running as a part of a Prestashop work, so I wouldn't want to play with the core code a lot. Otherwise, a number of workarounds as in your example, could be surely possible. – torillt May 29 '13 at 00:08