home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / grab_globals.lib.php < prev    next >
Encoding:
PHP Script  |  2003-11-26  |  1.9 KB  |  69 lines

  1. <?php
  2. /* $Id: grab_globals.lib.php,v 2.4 2003/11/26 22:52:23 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) {
  16.     if (!is_array($array)) {
  17.         return FALSE;
  18.     }
  19.     $is_magic_quotes = get_magic_quotes_gpc();
  20.     foreach($array AS $key => $value) {
  21.         if (is_array($value)) {
  22.             // there could be a variable coming from a cookie of
  23.             // another application, with the same name as this array
  24.             unset($target[$key]);
  25.  
  26.             PMA_gpc_extract($value, $target[$key]);
  27.         } else if ($is_magic_quotes) {
  28.             $target[$key] = stripslashes($value);
  29.         } else {
  30.             $target[$key] = $value;
  31.         }
  32.     }
  33.     return TRUE;
  34. }
  35.  
  36. if (!empty($_GET)) {
  37.     PMA_gpc_extract($_GET, $GLOBALS);
  38. } // end if
  39.  
  40. if (!empty($_POST)) {
  41.     PMA_gpc_extract($_POST, $GLOBALS);
  42. } // end if
  43.  
  44. if (!empty($_FILES)) {
  45.     foreach($_FILES AS $name => $value) {
  46.         $$name = $value['tmp_name'];
  47.         ${$name . '_name'} = $value['name'];
  48.     }
  49. } // end if
  50.  
  51. if (!empty($_SERVER)) {
  52.     $server_vars = array('PHP_SELF', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_AUTHORIZATION');
  53.     foreach ($server_vars as $current) {
  54.         if (isset($_SERVER[$current])) {
  55.             $$current = $_SERVER[$current];
  56.         } elseif (!isset($$current)) {
  57.             $$current = '';
  58.         }
  59.     }
  60.     unset($server_vars, $current);
  61. } // end if
  62.  
  63. // Security fix: disallow accessing serious server files via "?goto="
  64. if (isset($goto) && strpos(' ' . $goto, '/') > 0 && substr($goto, 0, 2) != './') {
  65.     unset($goto);
  66. } // end if
  67.  
  68. ?>
  69.