title: Check if a User is Logged On In a PHP Login System
body: <p>I'm relatively new to PHP and have been making a PHP login system. It works fine and all, but I'm wondering if there's a cleaner and more efficient way to check if a user is logged in. At the current moment my code looks like this:</p>
  
  <pre><code>session_start();
  if(isset($_SESSION['username']))
  {
  Echo "*Whole bunch of HTML*";
  }
  else{
  header("location:index.php");
  end();
  }
  </code></pre>
  
  <p>I want to make it to where the if statement checks if the user is logged in and nothing more, rather than having the if statement check if the user is logged in then displaying the page within in the if statement. Is this possible? </p>