home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / grab_globals.lib.php < prev    next >
Encoding:
PHP Script  |  2005-03-03  |  2.6 KB  |  89 lines

  1. <?php
  2. /* $Id: grab_globals.lib.php,v 2.5.4.5 2005/03/03 20:39:28 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * This library grabs the names and values of the variables sent or posted to a
  8.  * script in the $_* arrays and sets simple globals variables from them. It does
  9.  * the same work for the $PHP_SELF, $HTTP_ACCEPT_LANGUAGE and
  10.  * $HTTP_AUTHORIZATION variables.
  11.  *
  12.  * loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
  13.  */
  14.  
  15. function PMA_gpc_extract($array, &$target, $sanitize = TRUE) {
  16.     if (!is_array($array)) {
  17.         return FALSE;
  18.     }
  19.     $is_magic_quotes = get_magic_quotes_gpc();
  20.     foreach ($array AS $key => $value) {
  21.         /**
  22.          * 2005-02-22, rabus:
  23.          *
  24.          * This is just an ugly hotfix to avoid changing internal config
  25.          * parameters.
  26.          *
  27.          * Currently, the following variable names are rejected when found in
  28.          * $_GET or $_POST: cfg, GLOBALS, str* and _*
  29.          *
  30.          * Warning: this also affects array keys:
  31.          * Variables like $_GET['harmless']['cfg'] will also be rejected!
  32.          */
  33.         if ($sanitize && is_string($key) && (
  34.             $key == 'cfg'
  35.             || $key == 'GLOBALS'
  36.             || substr($key, 0, 3) == 'str'
  37.             || $key{0} == '_')) {
  38.             continue;
  39.         }
  40.  
  41.         if (is_array($value)) {
  42.             // there could be a variable coming from a cookie of
  43.             // another application, with the same name as this array
  44.             unset($target[$key]);
  45.  
  46.             PMA_gpc_extract($value, $target[$key], FALSE);
  47.         } else if ($is_magic_quotes) {
  48.             $target[$key] = stripslashes($value);
  49.         } else {
  50.             $target[$key] = $value;
  51.         }
  52.     }
  53.     return TRUE;
  54. }
  55.  
  56. if (!empty($_GET)) {
  57.     PMA_gpc_extract($_GET, $GLOBALS);
  58. } // end if
  59.  
  60. if (!empty($_POST)) {
  61.     PMA_gpc_extract($_POST, $GLOBALS);
  62. } // end if
  63.  
  64. if (!empty($_FILES)) {
  65.     foreach ($_FILES AS $name => $value) {
  66.         $$name = $value['tmp_name'];
  67.         ${$name . '_name'} = $value['name'];
  68.     }
  69. } // end if
  70.  
  71. if (!empty($_SERVER)) {
  72.     $server_vars = array('PHP_SELF', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_AUTHORIZATION');
  73.     foreach ($server_vars as $current) {
  74.         if (isset($_SERVER[$current])) {
  75.             $$current = $_SERVER[$current];
  76.         } elseif (!isset($$current)) {
  77.             $$current = '';
  78.         }
  79.     }
  80.     unset($server_vars, $current);
  81. } // end if
  82.  
  83. // Security fix: disallow accessing serious server files via "?goto="
  84. if (isset($goto) && strpos(' ' . $goto, '/') > 0 && substr($goto, 0, 2) != './') {
  85.     unset($goto);
  86. } // end if
  87.  
  88. ?>
  89.