title: php showing logout button only if logged in
body: <p>
  I am writing the code for a simple website where users log in and out and some other basic functions. I would like it to be so when anyone logs in, a logout button  is shown on all the pages they visit, and hidden if they are not logged it. I am still new and cannot figure out what is wrong. The logout button appears as soon as i initially click the login button, but when i navigate to other pages the button disappears from my menu.</p>
  
  
  
  <p>menu.php</p>
  
  <pre><code>$currentfile = basename($_SERVER['PHP_SELF']);
  if($currentfile = basename($_SERVER['PHP_SELF'])){
      if (isset($_SESSION['ID'])) {
          echo "&lt;a href=\"index.php\"&gt;Home&lt;/a&gt;
          &lt;a href=\"viewlist.php\"&gt;See Reviews&lt;/a&gt;
          &lt;a href=\"example11.php\"&gt;Write a Review&lt;/a&gt;
          &lt;a href=\"search.php\"&gt;Search&lt;/a&gt;
          &lt;a href='logoutconfirmation.php'&gt;Logout&lt;/a&gt;
          &lt;hr /&gt;";
      }else{
          echo "&lt;a href=\"index.php\"&gt;Home&lt;/a&gt;
          &lt;a href=\"viewlist.php\"&gt;See Reviews&lt;/a&gt;
          &lt;a href=\"example11.php\"&gt;Write a Review&lt;/a&gt;
          &lt;a href=\"search.php\"&gt;Search&lt;/a&gt;
          &lt;hr /&gt;";
      }
  } ?&gt;
  </code></pre>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
      include "header.inc.php";
      $pagetitle= "Login Form";
      $showform =1;
      $errormsg =0;
      $errorusername = $errorpassword = "";
      $inputdate = time();
  
      //FIRST CHECK TO SEE IF THE USER IS LOGGED IN
      if(isset($_SESSION['ID']))
      {
          echo "&lt;p class='error'&gt; You are already logged in. &lt;/p&gt;";
          include_once "footer.inc.php";
          exit();
      }
      if(isset ($_POST['submit'])) {
  
          /*************************************************************
          * ALL FIELDS- STORE USER DATA; SANITIZE USER-ENTERED DATA
          *************************************************************/
          $formfield['username'] = trim($_POST['username']);
          $formfield['password'] = trim($_POST['password']);
  
          if (empty($formfield['username'])) {
              $errorusername = "The username is required.";
              $errormsg = 1;
          }
          if (empty($formfield['password'])) {
              $errorpassword = "The password is required.";
              $errormsg = 1;
          }
  
          if ($errormsg != 0) {
              echo "&lt;p class='error'&gt; THERE ARE ERRORS!&lt;/p&gt;";
          } else {
              //get the user data from the database
              try {
                  $user = "SELECT * FROM Users WHERE username =:username";
                  $stmt = $pdo-&gt;prepare($user);
                  $stmt-&gt;bindValue(':username', $formfield['username']);
                  $stmt-&gt;execute();
                  $row = $stmt-&gt;fetch();
                  $countuser = $stmt-&gt;rowCount();
  
                  // if query okay, see if there is a result
                  if ($countuser &lt; 1) {
                      echo "&lt;p class='error'&gt; *This user cannot be found in the 
   database* &lt;/p&gt;";
                  } else {
                      if (password_verify($formfield['password'], $row['password'])) {
                      $_SESSION['ID'] = $row['ID'];
                      $showform = 0;
                      header("LocationL confirm.php?state=2");
                      echo "&lt;p&gt; Thank you for logging in! &lt;/p&gt;";
                  } else {
                      echo "&lt;p class='error'&gt; The username and password 
  combinations you entered are not correct. Please try again! &lt;/p&gt;";
                  }
              }//username exists
          } catch (PDOException $e) {
              echo 'ERROR fetching users: ' . $e-&gt;getMessage();
              exit();
          }
      }
  }
  if($showform == 1) {
      ?&gt;
      &lt;p class="homemsg"&gt;Welcome to the Movie Review Hub! Feel free to look 
  around or sign in to write your own review.&lt;/p&gt;
  
      &lt;form name="login" id="login" method="post" action="index.php"&gt;
          &lt;table class="center"&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;label for="username"&gt;Username: &lt;/label&gt;&lt;/th&gt;
                  &lt;td&gt;&lt;input name="username" id="username" type="text" placeholder="Required Username"
                     }?&gt;&lt;span class="error" &lt;?php if (isset($errorusername)) {
                  echo $errorusername;
              } ?&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;label for="password"&gt;Password: &lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input name="password" id="password" type="password" placeholder="Required Password"
                     }?&gt;&lt;span class="error"&gt; &lt;?php if (isset($errorpassword)) {
                  echo $errorpassword;
              } ?&gt;&lt;/span&gt;&lt;/td&gt;
          &lt;tr&gt;
              &lt;th&gt;&lt;label for="submit"&gt;Submit: &lt;/label&gt;&lt;/th&gt;
              &lt;td&gt;&lt;input type="submit" name="submit" id="submit" value="submit"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
  
      &lt;p&gt;&lt;a href=index.php&gt;Register.&lt;/a&gt;&lt;/p&gt;
  
      &lt;?php
      include_once "footer.inc.php";
  }
  ?&gt;
  </code></pre>
  
  <p>
  Like I said i would like the logout button to be show on all of the pages if someone logs in from the index page, the menu is included in all of my files</p>
  
  <p>
  The logout button initially shows when i press the login button, but when i refresh the page or navigate to another page it goes away.</p>