8

I have a strange problem. I recently migrated my application from my local xampp installation to a SUSE Enterprise Server 11 and everything is working but this one thing drives me crazy and I can't find a solution.

When passing arrays either through GET or POST using this syntax:

search_dggs.php?latmin[]=52.447529&latmin[]=22&lonmin=17.56&lonmax=22.16

I only get the first element of latmin. Mind you that this is only a simple example I tried after the error occurred in other places where the passing of arrays is necessary.

print_r($_SERVER["QUERY_STRING"]); 

outputs

latmin[]=52.447529&latmin[]=22&lonmin=17.56&lonmax=22.16

but

print_r($_GET);

gives

Array
(
    [latmin] => Array
        (
            [0] => 52.447529
        )

    [lonmin] => 17.56
    [lonmax] => 22.16
)

Exactly the same happens with all POST requests.

I'm using PHP Version 5.3.8. I guess the problem is some Server configuration but I couldn't find anything about this problem.

Response to comments:

The same happens if I submit any number of variables.

parse_str($_SERVER["QUERY_STRING"]);
print_r($latmin);

gives

Array
(
    [0] => 52.447529
)

php.ini can be found here

You should be able to see the behaviour in action here

The source file of this php file is

<?php

    $test="latmin[]=52.447529&latmin[]=22&lonmin=23&lonmax=22.16";
    parse_str($test);
    print_r($latmin);
    phpinfo();

?>
cpaulik
  • 303
  • 1
  • 3
  • 13

6 Answers6

5

Well my System Admin did a system update and reboot and the issue is now fixed. No configuration files were changed.

cpaulik
  • 303
  • 1
  • 3
  • 13
  • System updates sometimes include PHP updates and all kinds of other goodies. You might never know what fixed it! – citizenen Apr 12 '12 at 17:40
  • Configuration was looking good as well in my eyes. You might have been running a PHP version which was buggy. – hakre Apr 14 '12 at 09:34
4

Tested on my server and it works fine for me:

_GET["latmin"]  

Array
(
    [0] => 52.447529
    [1] => 22
)

Look in your php.ini in the Data Handling section and see what the values are. Reset everything to default, restart the webserver and try again. PHP.ini Data Handling defaults

gspatel
  • 1,128
  • 8
  • 12
  • Yes I know that the code is right and it also works on my local XAMPP installation, but not on the new Server. If I don't find a solution I will reinstall and hope that this behaviour will go away, but it would be great to know how something like this can happen. The strange thing is that also parse_str gives the wrong output. My php.ini is posted above and I noticed nothing unusual in the data handling section. – cpaulik Apr 10 '12 at 11:53
  • We can isolate that it's not a php.ini problem as I've used your exact php.ini and get the correct results (2 latmins in an array). Run phpinfo(); and pass your get parameters to the page and tell me what it shows in the _GET section at the bottom. – gspatel Apr 11 '12 at 17:21
2

An example at the link prints Array ( [0] => 52.447529 ) every time even no variables were passed. So, seems that you have problem in code that is not linked with this code: `

$test="latmin[]=52.447529&latmin[]=22&lonmin=23&lonmax=22.16";
parse_str($test);
print_r($latmin);
phpinfo();

`

rdo
  • 3,872
  • 6
  • 34
  • 51
  • This is because I test the parse_str method which should print a 2 element array, but doesn't. The passed variables are contained at the end of phpinfo(); But maybe this was not very clear. – cpaulik Apr 12 '12 at 10:08
0

Hmm.. maybe its somehow related to that critical vulnerability bug ? Does your XAMPP has same PHP version as production? I know there might be similar issues if you post too much data (both in terms of file/post size and param quantity). How about upgrading to 5.3.10 ?

Artjom Kurapov
  • 6,115
  • 4
  • 32
  • 42
  • Hi, Yes my local installation on which it works has the same version as the SUSE Enterprise Server it doesn't work on. So I don't think it is version specific but some strange config problem. I will upgrade or reinstall soon if I don't find a solution. But it would be interesting to get to the bottom of this. – cpaulik Apr 12 '12 at 07:57
0

Try $_REQUEST instead of $_GET and/or $_POST

A.N.M. Saiful Islam
  • 2,118
  • 5
  • 28
  • 34
0

The most likely cause of this bug is that someone set "max_input_vars" to 0 or 1 in php.ini. "max_input_vars" defaults to 1000, and can be overridden in php.ini.

I encountered the same behavior recently with a different cause -- a security patch someone backported to a PHP 5.2 installation partially implemented "max_input_vars", but missed some important bits. Different cause, same outcome.

Relevant php source code can be found in main/php_variables.c. In php 5.3.8, the rubber was hitting the road in the php_register_variable_ex function.

There's a SAPI "treat_data" hook which php uses when parsing strings like "foo=bar&asdf[]=1&asdf[]=2" -- A different SAPI might have its own implementation of this.