title: PHP Checking if session is registered
body: <p>I am creating a simple login script, I have set everything up but I am having trouble with sessions. </p>
  
  <p>At the end of the login check page I have the following code:</p>
  
  <pre><code>$count = mysql_num_rows($result);
  if($count == 1){
      $_SESSION["username"] = 'username';
      $_SESSION["password"] = 'password';
      header("location:success.php");
  }else{
      echo "Wrong username or password";
  }
  </code></pre>
  
  <p>And on the success.php page I have the following:</p>
  
  <pre><code>&lt;?php
  session_start();
  if (!isset($_SESSION['username'])) {
      header ("Location: wrong.php");
  }
  ?&gt;
  
  &lt;html&gt;
      &lt;body&gt;
          Login Successful
      &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is that when a correct user and pass is entered it takes you to wrong.php, whereas it needs to redirect to wrong.php when someone visits success.php without logging in.</p>
  
  <p>I am quite new to sessions and would appreciate any help. Thanks.</p>