title: Killing off Global Session Variable as a logout button
body: <p>Hey Stackoverflow users,</p>
  
  <p>Since I was able to get some amazing help before with a problem I was stuck on for longer than I could remember I thought I would come at you with this.</p>
  
  <p>Working with a login system that authenticates the user and kills the session off but currently it's not recognizing the variables assigned to the session. After clicking the logout button everything seems like it's working but when doing a direct connect to the <strong>Members Page</strong> by typing it into the address bar it loads the page instead of redirecting to the login page.</p>
  
  <p><strong>Members.php</strong></p>
  
  <pre><code>&lt;?PHP
  session_start();
  if (!isset($_SESSION['username'])) {
  header('location:login.php');
  }
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;The Animator BETA&lt;/title&gt;
  &lt;style&gt;
  //CSS Has been removed as it's lengthy and unrelated to the issue.
  &lt;/style&gt;
  &lt;!--[if lt IE 9]&gt;
  
          &lt;script src="http://html5shim.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
  
      &lt;![endif]--&gt;        
  
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
            $(document).ready(function(){
  
                  $('#login-trigger').click(function(){
  
                      $(this).next('#login-content').slideToggle();
  
                      $(this).toggleClass('active');                  
  
  
  
                      if ($(this).hasClass('active')) $(this).find('span').html('&amp;#x25B2;')
  
                          else $(this).find('span').html('&amp;#x25BC;')
  
                      })
  
            });
  
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;header class="cf"&gt;
  
  &lt;nav style="text-align:center"&gt;&lt;a href="logout.php"&gt;Logout&lt;/a&gt;&lt;/nav&gt;
  
  &lt;/header&gt;
  
  &lt;h1 style="text-align:center"&gt; The Animator - BETA&lt;/h1&gt;
  &lt;hr /&gt;
  &lt;div id="nav" style="text-align:center"&gt;
  &lt;ul style="text-align:center"&gt;
  
  &lt;li&gt;&lt;a href= "#" &gt;&lt;strong&gt;Home&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;strong&gt;&lt;li&gt;&lt;a href= "industrial.html" &gt;Industrial&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "educational.html" &gt;Education&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "independent.html"  &gt;Independent&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "emergent.html"  &gt;Emergent&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "team.html" &gt;Team&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "project.html"  &gt;Project&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "budget.html" &gt;Budget&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "profile.html" &gt;Profile&lt;/a&gt;&lt;/li&gt;&lt;/strong&gt;
  
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;hr /&gt;
  &lt;div style="padding-left:19%"&gt;&lt;input type="text" value="search" /&gt;
  &lt;input type="button" value="Search!" name="search"/&gt;
  &lt;/div&gt;
  &lt;div&gt;&amp;nbsp;&lt;/div&gt;
  &lt;div align="center"&gt;
  &lt;div&gt;&lt;img src="logo.png" width="407" height="345" alt="Logo" usemap="sectors" /&gt;&lt;/div&gt;
  
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;map name="sectors"&gt;
    &lt;area shape="rect" coords="72,40,194,165" alt="Industrial" href="industrial.html"&gt;
    &lt;area shape="rect" coords="210,38,328,162" alt="Emergent" href="emergent.html"&gt;
    &lt;area shape="rect" coords="208,178,331,296" alt="Independent" href="independent.html"&gt;
      &lt;area shape="rect" coords="71,177,194,295" alt="Educational" href="educational.html"&gt;
  
  &lt;/map&gt;
  &lt;div&gt;&amp;nbsp;&lt;/div&gt;
  &lt;div style="text-align:right"&gt;&lt;/div&gt;
  &lt;div&gt;&amp;nbsp;&lt;/div&gt;   
  &lt;div id="footer"&gt; &lt;hr /&gt;
    &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;a href="about.html"&gt;About The Animator&lt;/a&gt; | &lt;a href="contact.html"&gt;Contact&lt;/a&gt; | &lt;a href="privacy.html"&gt;Privacy Policy&lt;/a&gt; | &lt;a href="faq.html"&gt;FAQ&lt;/a&gt;&lt;/u&gt;&lt;/strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>LOGIN PAGE</strong></p>
  
  <pre><code>&lt;?php
  
  error_reporting(E_ALL);
  ini_set('display_errors',"On");
  
  include ('database_connection.php');
  if (isset($_POST['formsubmitted'])) {
      // Initialize a session:
  session_start();
      $error = array();//this aaray will store all error messages
  
  
      if (empty($_POST['e-mail'])) {//if the email supplied is empty 
          $error[] = 'You forgot to enter  your Email ';
      } else {
  
  
          if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {
  
              $Email = $_POST['e-mail'];
          } else {
               $error[] = 'Your Email Address is invalid  ';
          }
  
  
      }
  
  
      if (empty($_POST['Password'])) {
          $error[] = 'Please Enter Your Password ';
      } else {
          $Password = $_POST['Password'];
      }
  
  
         if (empty($error))//if the array is empty , it means no error found
      { 
  
  
  
          $query_check_credentials = "SELECT * FROM account WHERE (email='$Email' AND passwords='$Password')";
  
  
  
          $result_check_credentials = mysqli_query($dbc, $query_check_credentials);
          if(!$result_check_credentials){//If the QUery Failed 
              echo 'Query Failed ';
          }
  
          if (@mysqli_num_rows($result_check_credentials) == 1)//if Query is successfull 
          { // A match was made.
  
  
  
  
  
              $_SESSION = mysqli_fetch_array($result_check_credentials, MYSQLI_ASSOC);//Assign the result of this query to SESSION Global Variable
  
              $_SESSION['email'] = $Email; 
  
             session_start("username");
  
              header("Location: members.php");
  
  
  
          }else
          { 
  
              $msg_error= 'Either Your Account is inactive or Email address /Password is Incorrect';
          }
  
      }  else {
  
  
  
  echo '&lt;div class="errormsgbox"&gt; &lt;ol&gt;';
          foreach ($error as $key =&gt; $values) {
  
              echo '  &lt;li&gt;'.$values.'&lt;/li&gt;';
  
  
  
          }
          echo '&lt;/ol&gt;&lt;/div&gt;';
  
      }
  
  
      if(isset($msg_error)){
  
          echo '&lt;div class="warning"&gt;'.$msg_error.' &lt;/div&gt;';
      }
      /// var_dump($error);
      mysqli_close($dbc);
  
  } // End of the main Submit conditional.
  
  
  
  ?&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Login Form&lt;/title&gt;
  
  
  
  
  
  &lt;style type="text/css"&gt;
  body {
      font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
      font-size:12px;
  }
  .registration_form {
      margin:0 auto;
      width:500px;
      padding:14px;
  }
  label {
      width: 10em;
      float: left;
      margin-right: 0.5em;
      display: block
  }
  .submit {
      float:right;
  }
  fieldset {
      background:#EBF4FB none repeat scroll 0 0;
      border:2px solid #B7DDF2;
      width: 500px;
  }
  legend {
      color: #fff;
      background: #80D3E2;
      border: 1px solid #781351;
      padding: 2px 6px
  }
  .elements {
      padding:10px;
  }
  p {
      border-bottom:1px solid #B7DDF2;
      color:#666666;
      font-size:11px;
      margin-bottom:20px;
      padding-bottom:10px;
  }
  a{
      color:#0099FF;
  font-weight:bold;
  }
  
  /* Box Style */
  
  
   .success, .warning, .errormsgbox, .validation {
      border: 1px solid;
      margin: 0 auto;
      padding:10px 5px 10px 60px;
      background-repeat: no-repeat;
      background-position: 10px center;
       font-weight:bold;
       width:450px;
  
  }
  
  .success {
  
      color: #4F8A10;
      background-color: #DFF2BF;
      background-image:url('images/success.png');
  }
  .warning {
  
      color: #9F6000;
      background-color: #FEEFB3;
      background-image: url('images/warning.png');
  }
  .errormsgbox {
  
      color: #D8000C;
      background-color: #FFBABA;
      background-image: url('images/error.png');
  
  }
  .validation {
  
      color: #D63301;
      background-color: #FFCCBA;
      background-image: url('images/error.png');
  }
  
  
  
  &lt;/style&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  
  &lt;form action="login.php" method="post" class="registration_form"&gt;
    &lt;fieldset&gt;
      &lt;legend&gt;Login Form  &lt;/legend&gt;
  
      &lt;p&gt;Enter Your username and Password Below  &lt;/p&gt;
  
      &lt;div class="elements"&gt;
        &lt;label for="name"&gt;Email :&lt;/label&gt;
        &lt;input type="text" id="e-mail" name="e-mail" size="25" /&gt;
      &lt;/div&gt;
  
      &lt;div class="elements"&gt;
        &lt;label for="Password"&gt;Password:&lt;/label&gt;
        &lt;input type="password" id="Password" name="Password" size="25" /&gt;
      &lt;/div&gt;
      &lt;div class="submit"&gt;
       &lt;input type="hidden" name="formsubmitted" value="TRUE" /&gt;
        &lt;input type="submit" value="Login" /&gt;
      &lt;/div&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;button onclick="window.location='theanimator.html';"&gt;Go Back!&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>LOGOUT</strong></p>
  
  <pre><code>&lt;?php
  unset($_SESSION['email']);
  header('Location: login.php');
  exit;
  ?&gt;
  </code></pre>