Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Algimantas Stancelis

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Emulate register_globals off

   1  
   2  function unregister_GLOBALS()
   3  {
   4  if (!ini_get('register_globals')) {
   5         return;
   6     }
   7  
   8     // Might want to change this perhaps to a nicer error
   9     if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
  10         die('GLOBALS overwrite attempt detected');
  11     }
  12  
  13     // Variables that shouldn't be unset
  14     $noUnset = array('GLOBALS',  '_GET',
  15                       '_POST',    '_COOKIE',
  16                       '_REQUEST', '_SERVER',
  17                       '_ENV',    '_FILES');
  18  
  19     $input = array_merge($_GET,    $_POST,
  20                           $_COOKIE, $_SERVER,
  21                           $_ENV,    $_FILES,
  22                           isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
  23    
  24     foreach ($input as $k => $v) {
  25         if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
  26             unset($GLOBALS[$k]);
  27         }
  28     }
  29  }
  30  
  31  unregister_GLOBALS();


Source: http://www.zend.com/manual/faq.misc.php#faq.misc.registerglobals
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS