title: How to unset global variable in php?
body: <p>I know very basic of php and web programming. Here is my php code. I have seen couple of similar questions. They unset global variable with unset function. I want every time user open the url, a username and password prompt and after entering username password if it is correct download the file and delete username and password and if is wrong delete username and password and again prompt for username password.</p>
  
  <pre><code>&lt;?php    
      function destroy_foo()
      {
          if (isset($_SERVER['PHP_AUTH_USER'])) {
              unset($_SERVER['PHP_AUTH_USER']);       
          }
          if (isset($_SERVER['PHP_AUTH_PW'])) {
              unset($_SERVER['PHP_AUTH_PW']);
          }
      }
  
      if (!isset($_SERVER['PHP_AUTH_USER'])) {
  
          header('WWW-Authenticate: Basic realm="My Realm"');
          header('HTTP/1.0 401 Unauthorized');
          echo 'Text to send if user hits Cancel button';
          exit;
      } else {
  
          echo "&lt;p&gt;Hello {$_SERVER['PHP_AUTH_USER']}.&lt;/p&gt;";
          echo "&lt;p&gt;You entered {$_SERVER['PHP_AUTH_PW']} as your password.&lt;/p&gt;";
  
          $file = 'welcome.txt';
          if($_SERVER['PHP_AUTH_PW'] == "admin" &amp;&amp; $_SERVER['PHP_AUTH_USER'] =="admin"){
              destroy_foo();
  
              if (file_exists($file)) {
  
                 //Do some task
                  destroy_foo();
                  exit;
              }
          }
          else
          {
              //Do some task
              destroy_foo();
  
          }
      }
      ?&gt;
  </code></pre>
  
  <p>At the moment username and password stays in the global variables for some reason. I'd appreciate if you could give suggestion or hint.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This did not work either:</p>
  
  <pre><code>function destroy_foo()
  {
  
      if (isset($_SERVER['PHP_AUTH_USER'])) {
  
          unset($_SERVER['PHP_AUTH_USER']);
          $_SERVER['PHP_AUTH_USER'] = null;
  
      }
  
     if (isset($_SERVER['PHP_AUTH_PW'])) {
  
         unset($_SERVER['PHP_AUTH_PW']);
         $_SERVER['PHP_AUTH_PW'] = null;
  
     }
  }
  </code></pre>
  
  <p>Link to file: <a href="http://behzadgarekani.net16.net/" rel="nofollow noreferrer">http://behzadgarekani.net16.net/</a></p>