Query variable can be no longer than 512 character

2020-04-21 04:39发布

问题:

I'm struggling to read query variables that contain more than 512 characters in the $_GET array. If I parse the query string using parse_string, however, I can read it just fine from the resulting array.

Example:

# GET /test.php?foo=<string with 513 characters>&bar=bar HTTP/1.1

<?php
var_dump($_GET['foo']); # NULL
var_dump($_GET['bar']); # "bar"

parse_str($_SERVER['QUERY_STRING'], $output);
var_dump($output['foo']); # <string with 513 characters>
?>

This makes no sense to me, since $_GET uses parse_str internally to derive the query variables from the query string. Am I missing something?

回答1:

There is a PHP bug report. #50449

GET parameters with a value longer than 512 characters don't show up in the $_GET and $_REQUEST arrays. We've noticed this since upgrading to 5.3.1

It says there that it is Suhosin causing the behaviour.



标签: php suhosin