title: php. Trying to access $_SESSION variables gives index error
body: <p>Trying to access $_SESSION['key'] gives me index error. </p>
  
  <p>I need to check if <em>$_SESSION['loggedin']</em> is set to <em>true</em> in order to display a login/logout button. </p>
  
  <pre><code>//GENERAL IDEA 
  if( $_SESSION['loggedin'] == true ){
      //log out 
  }else{
      //log in
  }
  </code></pre>
  
  <p>But its ALWAYS executing the <em>else</em> and displaying the login button. </p>
  
  <p>After a while, I tried to echo the <em>$_SESSIONS['loggedin']</em> value and I get an index error. Checking isset() on the $_SESSION returns false.</p>
  
  <p>So I think the problem is that my <em>$_SESSION['loggedin']</em> isnt working like I think.</p>
  
  <p>I do have:</p>
  
  <ul>
  <li><p>session_start() at the top of my file.</p></li>
  <li><p>.php extensions on all my files. </p></li>
  </ul>
  
  <hr>
  
  <p><em>login.php</em> creates <em>$_SESSION['loggedin']</em> if successfully login in. (I know I am successfully loggedin bc I am getting redirected.)</p>
  
  <pre><code>if( $_POST['username'] == "myUSER" &amp;&amp; $_POST['password'] == "myPASSWORD" ){
      $_SESSION['loggedin'] == true;
      header( "location: ../main/home.php" );
      exit;
  }else {
      $bad_login == true;
  }
  </code></pre>
  
  <hr>
  
  <p><em>Authentication.php loggedin()</em> class function checks if <em>$_SESSION['loggedin']</em> isset and true to return true</p>
  
  <pre><code>public static function loggedin(){
      return ( isset( $_SESSION['loggedin'] ) &amp;&amp; $_SESSION['loggedin'] == true );
  }
  </code></pre>
  
  <hr>
  
  <p><em>_template.php</em> contains the button display in the footer section. ( I copied my whole template file in here bc I want to point out that my start_session() is located at the top of my <em>home.php</em> file BUT I don't think that makes a difference. Or maybe its easier to notice my fault if the whole file is copied. )</p>
  
  <pre><code>&lt;?php
  $page_name = basename( $_SERVER['PHP_SELF']);
  $page_name_parts = explode( '.', $page_name );
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;meta name="viewport" content="width=device-width"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div class="container-fluid"&gt;
  
          &lt;header&gt;
              &lt;h1 id="top"&gt;Heading&lt;/h1&gt;
          &lt;/header&gt;
  
          &lt;?php
              //Flash::show_flash();
              require( $page_name_parts[0] . ".view.php" );
          ?&gt;
  
          &lt;footer&gt;
              &lt;!-- Login button --&gt;
              &lt;?php require_once( "../lib/Authentication.php" ); ?&gt;
              &lt;?php if( Authentication::loggedin() ): ?&gt;
                  &lt;a href=" ../authentication/logout.php"&gt;&lt;button class="btn1"&gt;Logout&lt;/button&gt;&lt;/a&gt;
              &lt;?php else : ?&gt;
                  &lt;a href=" ../authentication/login.php"&gt;&lt;button class="btn1"&gt;Login&lt;/button&gt;&lt;/a&gt;
              &lt;?php endif ?&gt;
  
              &lt;!-- Scroll TOP --&gt;
              &lt;a href="#top"&gt;&lt;span&gt;&lt;/span&gt;Top&lt;/a&gt;
          &lt;/footer&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>