note 92439 deleted from reserved.variables.get by peehaa
| From: | peehaa@php.net | Date: | Sun, 28 Apr 2019 10:58:48 +0000 |
| Subject: | note 92439 deleted from reserved.variables.get by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210849@lists.php.net to get a copy of this message | ||
Note Submitter: robotreply at gmail dot com
----
Parsing of GET/POST drops duplicate variables unless those variables have "[]" (PHP bugs
#10502, #15498 and #16195). Adding "[]" makes a mess of your javascript code, so here is a
small workaround to it.
This function basically scans your raw POST and GET input and tries to fix the same. This function
must be called near the top of your script. Optimizations are welcome.
<?php
function php_fix_raw_query() {
$post = '';
// Try globals array
if (!$post && isset($_GLOBALS) &&
isset($_GLOBALS["HTTP_RAW_POST_DATA"]))
$post = $_GLOBALS["HTTP_RAW_POST_DATA"];
// Try globals variable
if (!$post && isset($HTTP_RAW_POST_DATA))
$post = $HTTP_RAW_POST_DATA;
// Try stream
if (!$post) {
if (!function_exists('file_get_contents')) {
$fp = fopen("php://input", "r");
if ($fp) {
$post = '';
while (!feof($fp))
$post = fread($fp, 1024);
fclose($fp);
}
} else {
$post = "" . file_get_contents("php://input");
}
}
$raw = !empty($_SERVER['QUERY_STRING']) ? sprintf('%s&%s',
$_SERVER['QUERY_STRING'], $post) : $post;
$arr = array();
$pairs = explode('&', $raw);
foreach ($pairs as $i) {
if (!empty($i)) {
list($name, $value) = explode('=', $i, 2);
if (isset($arr[$name]) ) {
if (is_array($arr[$name]) ) {
$arr[$name][] = $value;
} else {
$arr[$name] = array($arr[$name], $value);
}
} else {
$arr[$name] = $value;
}
}
}
foreach ( $_POST as $key => $value ) {
if (is_array($arr[$key]) ) {
$_POST[$key] = $arr[$name];
$_REQUEST[$key] = $arr[$name];
}
}
foreach ( $_GET as $key => $value ) {
if (is_array($arr[$key]) ) {
$_GET[$key] = $arr[$name];
$_REQUEST[$key] = $arr[$name];
}
}
# optionally return result array
return $arr;
}
?>