title: How to use $GLOBALS to share variables across php files?
body: <p>I have a file, <code>index.php</code> that produces a link to a page that I want my user to <em>only</em> be able to access if some <code>$var == True</code>.</p>
  
  <p>I want to be able to do this through the $GLOBALS array, since my $_SESSION array is already being filled with instances of a specific class I want to manipulate further on.</p>
  
  <p>My <code>index.php</code> page:</p>
  
  <pre><code>&lt;?php
  
      $var = True;
  
      $GLOBALS["var"];
  
      echo "&lt;p&gt;&lt;a href='next.php'&gt;Click to go to next page&lt;/a&gt;&lt;/p&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>My <code>next.php</code> page:</p>
  
  <pre><code>&lt;?php
  
          if($GLOBALS["var"] == False)
              exit("You do not have access to this page!");
          else
              echo "&lt;p&gt;You have access!&lt;/p&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>Currently, <code>next.php</code> is echoing the exit text. Am I accessing/assigning to the $GLOBALS array correctly? Or am I not using it properly?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong>
  So I've tried some of the suggestions here. This is my new <code>index.php</code>:</p>
  
  <pre><code>&lt;?php
  
      $GLOBALS["var"] = True;
  
      echo "&lt;p&gt;&lt;a href='next.php'&gt;Click to go to next page&lt;/a&gt;&lt;/p&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>My <code>next.php</code>:</p>
  
  <pre><code>&lt;?php
  
      if($GLOBALS["var"] == False)
          exit("You do not have access to this page!");
      else
          echo "&lt;p&gt;You have access!&lt;/p&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>However, I'm still running into the same issue where the exit statement is being printed.</p>