title: Page accessible only if logged in
body: <p>Hello Stackoverflowers</p>
  
  <p>Im new to PHP and im trying to make a members area for my testpage. I have made a successful register and login page, but now when I changed the code so if I log in correctly it redirects my to a page, and if I log in with wrong information it send me to a different page. However the members area is accessible if you type the location in the address-bar. Now, here's what I need help with, When someone tries to access that location without being logged in it should say "Access denied" but when you log in, it should redirect you to the members area and all it content is shown.</p>
  
  <p>Here is my code:</p>
  
  <p>login.php</p>
  
  <pre><code>&lt;?php
  session_start();
    $host = 'localhost';
    $user = 'root';
    $pass = '';
    $db = 'Data';
  
  mysql_connect($host, $user, $pass);
  mysql_select_db($db);
  
   if(isset($_POST['username'])) {
      $username = $_POST['username'];
      $password = $_POST['password'];
      $sql = "SELECT * FROM Project WHERE username='$username' AND password='$password' LIMIT 1";
      $res = mysql_query($sql);
      if (mysql_num_rows($res) == 1){
        header("Location: loggedin.php");
        exit();
      } else {
        echo 'Anv&amp;auml;ndarnamn eller l&amp;ouml;senord st&amp;auml;mmer ej med informationen i databasen, var sn&amp;auml;ll f&amp;ouml;rs&amp;ouml;k igen &lt;br&gt;';
        echo '&lt;a href="login.php"&gt;G&amp;aring; tillbaka&lt;/a&gt; Eller &lt;a href="signup.php"&gt;Registrera dig&lt;/a&gt;';
  
        exit();
      }
    }
  ?&gt;
  
  
  &lt;html&gt;
  
  &lt;head&gt;
  
    &lt;meta charset="UTF-8"&gt;
  
    &lt;title&gt;Logga in&lt;/title&gt;
  
      &lt;script src="js/prefixfree.min.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
    &lt;div class="body"&gt;&lt;/div&gt;
          &lt;div class="grad"&gt;&lt;/div&gt;
      &lt;div class="wrapper"&gt;
          &lt;div class="header"&gt;
              &lt;div&gt;bababa&lt;span&gt;bababa&lt;/span&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;br&gt;
          &lt;div class="login"&gt;
        &lt;form method="post" action="login.php"&gt;
                  &lt;input type="text" placeholder="Anv&amp;auml;ndarnamn" name="username" required&gt;&lt;br&gt;
                  &lt;input type="password" placeholder="L&amp;ouml;senord" name="password" required&gt;&lt;br&gt;
                  &lt;input type="submit" value="Logga in"&gt;
        &lt;/form&gt;
          &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;script src='http://codepen.io/assets/libs/fullpage/jquery.js'&gt;&lt;/script&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>signup.php</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html lang="sv"&gt;
  &lt;head&gt;
  &lt;link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'&gt;
  &lt;link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'&gt;
  &lt;script src="http://code.jquery.com/jquery-1.11.2.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" &gt;
  $(".name").focus(function(){
    $(".name-help").slideDown(500);
  }).blur(function(){
    $(".name-help").slideUp(500);
  });
  
  $(".email").focus(function(){
    $(".email-help").slideDown(500);
  }).blur(function(){
    $(".email-help").slideUp(500);
  });
  
  
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;div class="wrapper"&gt;
    &lt;h1&gt;Registrera er h&amp;auml;r&lt;/h1&gt;
    &lt;p&gt;Detta &amp;auml;r ett test-formul&amp;auml;r f&amp;ouml;r Webbutvecklingsprojektet. Skriv ditt namn h&amp;auml;r
    under och om allt funkar r&amp;auml;tt skall systemet lagra ditt namn i en MySQL databas.&lt;/p&gt;
  
    &lt;form class="form" name="form" method="post" action="add.php"&gt;
  
       &lt;input type="text" id="username" name="username" placeholder="Anv&amp;auml;ndarnamn" required&gt;
  
       &lt;input type="password" id="password" name="password" placeholder="L&amp;ouml;senord" required&gt;
  
   &lt;input type="email" id="email" name="email" placeholder="E-mail" required&gt;
  
  
      &lt;input type="submit" class="submit" value="Registrera dig"&gt;
  
    &lt;/form&gt;
  
    &lt;h3&gt;
      Allm&amp;auml;nt &amp; regler:
    &lt;/h3&gt;
    &lt;ul&gt;
      &lt;li&gt;Maximalt 2GB Lagring&lt;/li&gt;
      &lt;li&gt;Du m&amp;aring;ste skriva f&amp;ouml;r- och efternamn&lt;/li&gt;
      &lt;li&gt;Databasen lagrar bara upp till 60 anv&amp;auml;ndare&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;p class="optimize"&gt;
  &lt;/p&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And last: loggedin.php</p>
  
  <pre><code> &lt;?php
  session_start();
    $host = 'localhost';
    $user = 'root';
    $pass = '';
    $db = 'Data';
  
  mysql_connect($host, $user, $pass);
  mysql_select_db($db);
  
     if(!isset($_SESSION['username'])) {
     die("Please login");
  } else {
  echo 'Du &amp;auml;r inloggad';
  }
  ?&gt;
  </code></pre>
  
  <p>FTR: I tried the if isset but even when I logged in correctly the same message shows up: Please log in, how should I fix this?</p>
  
  <p>Im a newbie at this so help me a bit extra</p>
  
  <p>Thank you!</p>