note 58926 added to language.variables.external
| From: | IMarvinTPA at bigfoot dot com | Date: | Mon, 21 Nov 2005 05:52:36 +0000 |
| Subject: | note 58926 added to language.variables.external | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98869@lists.php.net to get a copy of this message | ||
I saw a note from
jan.gacioch at motorola dot com
posted on
19-Feb-2004 11:52
"Just a correction regarding 'cscotti@ifrance' contribution: code '$first =
$item_value;' should be place just BEFORE the 'else if' condition and NOT
AFTER."
This is not true, if the form has things posted in an unusual order, the $first value will be from a
completely different variable.
Also, nobody mentioned this, but in the PHP.ini file there is an option called
"always_populate_raw_post_data". It'll fill in that variable. It took me a while to
find it.
I think it is bad to consider form name fields to be case sensitive, so my version uses all
uppercase form values.
I also use a Request function to pull the data out of the global variables so I don't get
warnings or errors when I try to access an undefined variable. I usually just want an empty string
for them. (I have the same for Session and Server.)
UCase is shorter than strtoupper and I have a lot of converted ASP code and it was easier to create
alias functions than to replace them.
<?
$_ATBREQUEST = multi_post_item();
function multi_post_item() {
$rawpost = Globals('HTTP_RAW_POST_DATA');
$array_output = array();
$raw_input_items = split("&", addbit3(Server("QUERY_STRING"), $rawpost,
"&"));
foreach ($raw_input_items as $input_item) {
// split this item into name/value pair
//Print $input_item . BR;
if ($input_item != "") {
$item = split("=", $input_item);
// form item name
$item_name = ucase(urldecode($item[0]));
// form item value
if (empty($item[1]))
$item_value = "";
else
$item_value = urldecode($item[1]);
if ( !isset($array_output[$item_name]) ) {
$array_output[$item_name] = $item_value;
} elseif ( !is_array($array_output[$item_name]) ) {
$first = $array_output[$item_name];
$array_output[$item_name] = array();
$array_output[$item_name][]= $first;
$array_output[$item_name][]= $item_value;
} else {
$array_output[$item_name][]= $item_value;
}
}
}
return $array_output;
}
function Request2($param){
if (empty($_REQUEST[$param])) {
return "";
}
else
return $_REQUEST[$param];
}
function Request($param){
global $_ATBREQUEST;
$uparam = ucase($param);
if (empty($_ATBREQUEST[$uparam])) {
return Request2($param);
}
else{
if (is_array($_ATBREQUEST[$uparam])){
return implode(", ", $_ATBREQUEST[$uparam]);
}
else
return $_ATBREQUEST[$uparam];
}
}
//We want the array
function RequestArray($param){
global $_ATBREQUEST;
$uparam = ucase($param);
if (empty($_ATBREQUEST[$uparam])) {
return array(Request2($param));
}
else{
return $_ATBREQUEST[$uparam];
}
}
//AddBit 1 and 2 are commas and semicolons respectively.
function AddBit3($mystr, $mynew, $mysep) {
if ($mystr . "" == "")
$mystr = $mynew;
else
$mystr .= $mysep . $mynew;
return $mystr;
}
function Server($param){
if (empty($_SERVER[$param]))
return "";
else
return $_SERVER[$param];
}
function UCase($str){
return strtoupper($str);
}
?>
----
Manual Page -- http://www.php.net/manual/en/language.variables.external.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58926
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58926&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58926&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58926&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58926&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58926&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58926&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58926&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58926&report=yes
Search -- http://master.php.net/manage/user-notes.php