Passed arrays lose all but first element

安稳与你 提交于 2019-12-01 00:53:13

问题


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();

?>

回答1:


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




回答2:


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




回答3:


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();

`




回答4:


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 ?




回答5:


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




回答6:


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.



来源:https://stackoverflow.com/questions/10026198/passed-arrays-lose-all-but-first-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!