title: PHP blank page after the login
body: <p>I'm building a CMS for a website. The problem is that after the login a blank page appears and it stays until I hit refresh. Then it loads to the correct menu page and everything else is working correctly except this little detail. Any tips to solve this? Thanks, my code is below:</p>
  
  <pre><code>    &lt;?php
  
  session_start();
  
  include_once('../includes/connection.php');
  if(isset($_SESSION['logged_in'])) {
      //display index
      ?&gt;
  
      &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;AdminENG&lt;/title&gt;
          &lt;link rel ="stylesheet" href="../assets/style.css"/&gt;
      &lt;/head&gt;
  
          &lt;body&gt;
              &lt;div class="container"&gt;
                  CMS - ENG
                  &lt;ol&gt;
  
                      &lt;li&gt;&lt;a href ="add.php"&gt;Add Article&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href ="delete.php"&gt;Delete Article&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href ="logout.php"&gt;Logout&lt;/a&gt;&lt;/li&gt;
                  &lt;/ol&gt;
              &lt;/div&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  
      &lt;?php
  }
  else {
      //display login
      if(isset($_POST['username'], $_POST['password'])) {
          $username = $_POST['username'];
          $password = md5($_POST['password']);
  
          if (empty($username) || empty($password)) {
              $error = "All fields are required!";
          }
          else {
              $query = $pdo-&gt;prepare("SELECT * FROM users WHERE user_name = ? AND user_password = ?");
  
              $query-&gt;bindValue(1, $username);
              $query-&gt;bindValue(2, $password);
  
              $query-&gt;execute();
  
              $num = $query-&gt;rowCount();
  
              if($num == 1) {
                  //user entered the correct details
                  $_SESSION['logged_in'] = true;
  
                  header('Location: index.php');
                  exit();
              }
              else {
                  //user entered false details
                  $error = "Incorrect details!";
              }
          }
      }
  
      ?&gt;
  
      &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;AdminENG&lt;/title&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;link rel ="stylesheet" href="../assets/style.css"/&gt;
      &lt;/head&gt;
  
          &lt;body&gt;
              &lt;div class="container"&gt;
                  CMS
                  &lt;br&gt;&lt;br&gt;
  
                  &lt;?php
                  if (isset($error)) { ?&gt;
                      &lt;small style="color:#aa0000"&gt;&lt;?php echo $error; ?&gt;&lt;/small&gt;
  
                  &lt;?php } ?&gt;
  
                  &lt;br&gt;&lt;br&gt;
  
                  &lt;form action="index.php" method="post"&gt;
                      &lt;input type ="text" name="username" placeholder="Username"/&gt;
                      &lt;input type="password" name="password" placeholder="Password"/&gt;
                      &lt;input type="submit" value="Login"/&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  
      &lt;?php
  }
  ?&gt;
  </code></pre>