Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passed arrays lose all but first element

Tags:

arrays

post

php

get

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

?>
like image 799
cpaulik Avatar asked Apr 05 '12 09:04

cpaulik


3 Answers

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

like image 167
cpaulik Avatar answered Oct 19 '22 05:10

cpaulik


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

like image 40
gspatel Avatar answered Oct 19 '22 03:10

gspatel


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

`

like image 35
rdo Avatar answered Oct 19 '22 05:10

rdo