title: PHP does not redirect to a page after login
body: <p>I have a problem i have been trying to get my head around for a few days now. I have a website with many pages but the problem I have is that I am trying to run a session that when a user logs in, the navigation bar will change to something like "Hi user" with the option to log out or look at pages that are only accessible when the user is logged on. 
  Any help is greatly appreciated as i am completely hopeless about this right now as I really do not know where the error is.</p>
  
  <p>Page 1: login.php - this is where the user will log in.</p>
  
  <pre><code>&lt;?php
  include ('logon.php');
  ?&gt;
  &lt;html&gt;
  &lt;body&gt;
      &lt;?php
          include('navbar.php');
      ?&gt;
      &lt;form action="login.php" method="post" name="login" id="login"&gt;
                      Username:
                          &lt;br&gt;
                      &lt;input type="text" name="Username" required&gt;
                          &lt;br&gt;&lt;br&gt;
                      Password:
                          &lt;br&gt;
                      &lt;input type="password" name="Password" id="password" required&gt;
                          &lt;br&gt;&lt;br&gt;
                  &lt;input name="login" type="Submit" value="Login" id="Login"&gt;
              &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Page 2: logon.php - this is the page that fetches information from the database and runs the session.
      
  
  <pre><code>    $Username = $_POST['Username']; 
      $Password = $_POST['Password'];
  
      $S_Username = $_POST['S_Username']; 
      $Pass = $_POST['Password'];
  
      $Management_Username = $_POST['Management_Username']; 
      $Passwd = $_POST['Password'];
  
  $query = "SELECT COUNT(*) AS cnt FROM Clients WHERE Username='" . mysqli_real_escape_string($connection, $Username) . "' &amp;&amp; Password='" . mysqli_real_escape_string($connection, $Password). "'";
  $result = mysqli_query($connection, $query);
  $row = mysqli_fetch_assoc($result);
  
  $queryadmin = "SELECT COUNT(*) AS cnt FROM S_Organiser WHERE S_Username='" . mysqli_real_escape_string($connection, $S_Username) . "' &amp;&amp; Password='" . mysqli_real_escape_string($connection, $Pass). "'";
  $resultadmin = mysqli_query($connection, $queryadmin);
  $rowadmin = mysqli_fetch_assoc($resultadmin);
  
  $querymanagement = "SELECT COUNT(*) AS cnt FROM Management WHERE Username='" . mysqli_real_escape_string($connection, $Management_Username) . "' &amp;&amp; Password='" . mysqli_real_escape_string($connection, $Passwd). "'";
  $resultmanagement = mysqli_query($connection, $querymanagement);
  $rowmanagement = mysqli_fetch_assoc($resultmanagement);
  
  if ($row["cnt"] &gt; 0) 
  {
      $_SESSION["userlogged"] =  $Username;
      header("Location: sorganiser.php");
      die();
  } 
  else if ($rowadmin["cnt"] &gt; 0 )
      {
          $_SESSION["adminlogged"] = $S_Username;
          header("Location: logon.php");
      }
  else if ($rowmanagement["cnt"] &gt; 0 )
      {
          $_SESSION["managementlogged"] = $Management_Username;
          header("Location: logon.php");
      }
  else 
  {
      echo 'Not a valid login, please check your username and password!';
  }
  }
  ?&gt;
  </code></pre>
  
  <p>Page 3: navbar.php - this is the navigation bar page that should change once the session has started
      
  
  <pre><code>if(isset($_SESSION['userlogged']))
  {
      echo '&lt;div id="nav"&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="register.php"&gt;Register&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="login.php"&gt;Log In&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="admin.php"&gt;Admin&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href=""&gt;|&lt;/li&gt;
                  &lt;li class="Username"&gt; Hi '.$_SESSION['userlogged'].'&lt;/li&gt;      
                      &lt;li&gt;&lt;a href="logout.php"&gt;Logout&lt;/a&gt;&lt;/li&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;';
  }
  
  else if(isset($_SESSION['adminlogged']))
  {
      echo '&lt;div id="nav"&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="register.php"&gt;Register&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="login.php"&gt;Log In&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="admin.php"&gt;Admin&lt;/a&gt;&lt;/li&gt; 
                  &lt;a href=""&gt;|&lt;/li&gt;
                  &lt;li class="S_Username"&gt; Hi '.$_SESSION['adminlogged'].'&lt;/li&gt;      
                      &lt;li&gt;&lt;a href="logout.php"&gt;Logout&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="add.php"&gt;Products&lt;/a&gt;&lt;/li&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;';
  }
  else if(isset($_SESSION['managementlogged']))
  {
      echo '&lt;div id="nav"&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="register.php"&gt;Register&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="login.php"&gt;Log In&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="admin.php"&gt;Admin&lt;/a&gt;&lt;/li&gt; 
                  &lt;a href=""&gt;|&lt;/li&gt;
                  &lt;li class="Management_Username"&gt; Hi '.$_SESSION['managementlogged'].'&lt;/li&gt;      
                      &lt;li&gt;&lt;a href="logout.php"&gt;Logout&lt;/a&gt;&lt;/li&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;';
  }
  else
  {
  echo '&lt;div id="nav"&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="register.php"&gt;Register&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="login.php"&gt;Log In&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
                  &lt;a href="admin.php"&gt;Admin&lt;/a&gt;&lt;/li&gt; 
              &lt;/ul&gt;
          &lt;/div&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>Page 4: client.php - this is the page that the user will be able to see once they login.</p>
  
  <pre><code>&lt;?php
  session_start();
  if(!isset($_SESSION['userlogged'])) 
  {
  header('Location: logon.php?redirect=client.php');
  exit;
  }
  include ('logon.php');
  ?&gt;
  &lt;html&gt;
  &lt;body&gt;
      &lt;?php
          include('navbar.php');
      ?&gt;
      &lt;?if(!isset($_SESSION['userlogged'])) 
        {
        echo "Welcome" .$_SESSION['userlogged'].", this is your login page!";
        }
        else
        echo "You must be logged in to view this page."?&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thank you for your help in advance.</p>