note 58926 deleted from language.variables.external by danbrown

From: Date: Wed, 09 Mar 2011 14:36:11 +0000
Subject: note 58926 deleted from language.variables.external by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177697@lists.php.net to get a copy of this message
Note Submitter: IMarvinTPA at bigfoot dot com ---- 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); } ?>

« previous php.notes (#177697) next »