note 92439 added to reserved.variables.get
| From: | robotreply at gmail dot com | Date: | Fri, 24 Jul 2009 07:17:52 +0000 |
| Subject: | note 92439 added to reserved.variables.get | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158676@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 122.162.142.29
----
Manual Page -- http://www.php.net/manual/en/reserved.variables.get.php
Edit -- https://master.php.net/note/edit/92439
Del: integrated -- https://master.php.net/note/delete/92439/integrated
Del: useless -- https://master.php.net/note/delete/92439/useless
Del: bad code -- https://master.php.net/note/delete/92439/bad+code
Del: spam -- https://master.php.net/note/delete/92439/spam
Del: non-english -- https://master.php.net/note/delete/92439/non-english
Del: in docs -- https://master.php.net/note/delete/92439/in+docs
Del: other reasons-- https://master.php.net/note/delete/92439
Reject -- https://master.php.net/note/reject/92439
Search -- https://master.php.net/manage/user-notes.php