title: Unregistering Globals?
body: <p>I'm having trouble understading this function. I know what register_globals is and how long it has been depreciated from PHP but I'm looking at this code and I'm like, what in the?...</p>
  
  <pre><code>&lt;?php
      //Undo register_globals
      function unregister_globals() {
          if (ini_get(register_globals)) {
              $array = array('_REQUEST', '_SESSION', '_SERVER', '_ENV', '_FILES');
              foreach ($array as $value) {
                  foreach ($GLOBALS[$value] as $key =&gt; $var) {
                      if ($var === $GLOBALS[$key]) {
                          unset($GLOBALS[$key]);
                      }
                  }
              }
          }
      }
  ?&gt;
  </code></pre>
  
  <p>The part in which I'm not understanding is this...</p>
  
  <pre><code>foreach ($array as $value) {
      foreach ($GLOBALS[$value] as $key =&gt; $var) {
          if ($var === $GLOBALS[$key]) {
              unset($GLOBALS[$key]);
           }
       }
   }
  </code></pre>
  
  <p>This foreach loop is cycling through each value in $array we defined then the inner foreach loop is grabbing a super global array from GLOBALS whether it is _REQUEST, _SESSION, _SERVER, _ENV, _FILES, etc... Afterwords it seems like the condional is checking to see if $var is equal to a GLOBAL variable or what not. If so then we'll unset it.</p>
  
  <p>But I'm still having a major difficulty wrapping my head around this one...</p>
  
  <p><strong>UPDATE</strong>
  Here is the snippet of code I'm experimenting with and debugging. What happens if register_globals is on, and a hacker comes barreling along, inserts ?auth=1 into the query string? Will auth be deleted from GLOBALS or will it be echoed out? </p>
  
  <pre><code>if( true ) {
      $globals = array(
          '_COOKIE',
          '_GET',
          '_POST',
          '_REQUEST',
          '_SERVE',
          '_SESSION'
      );
  
      foreach($globals as $global) {
          foreach($GLOBALS[$global] as $k =&gt; $v) {
              /* $GLOBALS['_GET'] on the first loop; */
              /* IF WE SAY, $GLOBALS['app_dir'], WE GET THE VALUE */
  
              if( $v == $GLOBALS[$k] ) {
                  echo "K=&gt; " . $k . "&lt;br /&gt;";
                  echo "V =&gt; " . $v . "&lt;br /&gt;";
                  echo "GLOB =&gt; " . $GLOBALS[$k] . "&lt;br /&gt;";
              }
          }
      }
  
              echo $authorized; // a intentional non-defined variable
  
      //print_r($GLOBALS);
  }
  </code></pre>
  
  <p>Thanks for your time.</p>