note 52423 added to language.variables.external

From: Date: Sat, 30 Apr 2005 13:57:49 +0000
Subject: note 52423 added to language.variables.external
Groups: php.notes 
Request: Send a blank email to php-notes+get-88791@lists.php.net to get a copy of this message
This code module can be added to every form using require_once(). It will process any and all form data, prepending each variable with a unique identifier (so you know which method was used to get the data). My coding could be neater, but this sure makes processing forms much easier! <?php // ----------------------------------------------------------------- // Basic Data PHP module. This module captures all GET, POST // and COOKIE data and processes it into variables. // Coded April, 2005 by Timothy J. Pauly // www.timpauly.com // ----------------------------------------------------------------- // // coo_ is prepended to each cookie variable // get_ is prepended to each GET variable // pos_ is prepended to each POST variable // ses_ is prepended to each SESSION variable // ser_ is prepended to each SERVER variable session_start(); // initialize session data $ArrayList = array("_POST", "_GET", "_SESSION", "_COOKIE", "_SERVER"); // create an array of the autoglobal arrays // we want to process foreach($ArrayList as $gblArray) // process each array in the array list { $prefx = strtolower(substr($gblArray,1,3))."_"; // derive the prepend string // from the autoglobal type name $tmpArray = $$gblArray; $keys = array_keys($tmpArray); // extract the keys from the array being processed foreach($keys as $key) // process each key { $arcnt = count($tmpArray[$key]); if ($arcnt > 1) // Break down passed arrays and // process each element seperately { $lcount = 0; foreach ($tmpArray[$key] as $dval) { $prkey = $prefx.$key; // create a new key string // with the prepend string added $prdata['$prkey'] = $dval; // this step could be eliminated ${$prkey}[$lcount] = $prdata['$prkey']; //create new key and insert the data $lcount++; } } else { // process passed single variables $prkey = $prefx.$key; // create a new key string // with the prepend string added $prdata['$prkey'] = $tmpArray[$key]; // insert the data from // the old array into the new one $$prkey = $prdata['$prkey']; // create the newly named // (prepended) key pair using variable variables :-) } } } // ------------------------------------------------------------- ?> ---- Manual Page -- http://www.php.net/manual/en/language.variables.external.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52423 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52423&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52423&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52423&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52423&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52423&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52423&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88791) next »