cvs: phpweb /include prepend.inc
| From: | Gabor Hojtsy | Date: | Sat, 14 Dec 2002 19:03:09 +0000 |
| Subject: | cvs: phpweb /include prepend.inc | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-14183@lists.php.net to get a copy of this message | ||
goba Sat Dec 14 14:03:09 2002 EDT
Modified files:
/phpweb/include prepend.inc
Log:
Add the import_vars() function to make our life easier
in cases, when we need to import some variables from
an array into the global scope. This ensures security
if used properly, as no other variable can snap into the
global scope, only those explicitly requested.
This function is for future use in phpweb scripts.
Index: phpweb/include/prepend.inc
diff -u phpweb/include/prepend.inc:1.9 phpweb/include/prepend.inc:1.10
--- phpweb/include/prepend.inc:1.9 Sat Dec 14 07:41:50 2002
+++ phpweb/include/prepend.inc Sat Dec 14 14:03:08 2002
@@ -9,11 +9,12 @@
// from outside PHP. But it should be noted that these variables
// are not necessarily superglobals, so they need to be global-ed!
if (!isset($_SERVER)) {
- $_GET = &$HTTP_GET_VARS;
- $_POST = &$HTTP_POST_VARS;
- $_ENV = &$HTTP_ENV_VARS;
- $_SERVER = &$HTTP_SERVER_VARS;
- $_COOKIE = &$HTTP_COOKIE_VARS;
+ $_GET = &$HTTP_GET_VARS;
+ $_POST = &$HTTP_POST_VARS;
+ $_ENV = &$HTTP_ENV_VARS;
+ $_SERVER = &$HTTP_SERVER_VARS;
+ $_COOKIE = &$HTTP_COOKIE_VARS;
+ $_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
}
// Load in always required parts
@@ -25,5 +26,24 @@
// from there. It just defines $LAST_UPDATED, which is the
// mirror's last updated time.
include_once 'last_updated.inc';
+
+// Function used to import request vars to global scope.
+// Walks through $array, and import all values associated
+// with elements listed in $keys to the global scope
+function import_vars(&$array, $keys)
+{
+ // Wrong parameters passed
+ if (!is_array($array) || !is_array($keys)) { return FALSE; }
+
+ // Walk through all requested keys
+ foreach ($keys as $keyname) {
+
+ // If there is a value in the arary for this key,
+ // import it to the global scope (without copying)
+ if (isset($array[$keyname])) {
+ $GLOBALS[$keyname] = &$array[$keyname];
+ }
+ }
+}
?>