title: How do I create a very basic login script in PHP?
body: <p>I'm using <code>$_SESSION["user']</code> in admin.php and then calling <code>session_register("user")</code> in login.php. <code>session_register("user")</code> is not returning my user value.</p>
  
  <p>Currently when I want to forward to the admin page using <code>header("location:admin.php")</code> causes a loop whereby it returns the login page.</p>
  
  <p>Here is my form html <code>form.php</code>:</p>
  
  <pre><code>&lt;form action='login.php' method='post'&gt;
      Password:
      &lt;input type='password' name='password'&gt;
      &lt;input type='submit' value='Login'&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This page displays my admin area <code>admin.php</code>:</p>
  
  <pre><code>&lt;?php
  
  session_start();
  if (!isset($_SESSION["user"])) {
      include('form.php');
      }
  
  else    {
      echo "admin stuff";
      }
  
  ?&gt;
  </code></pre>
  
  <p>This is where you <code>login.php</code>:</p>
  
  <pre><code>&lt;?php
  
  session_start();
  include('functions.php');
  connect();
  
  $pass = $_POST['password'];
  $text = file_get_contents('pw.txt');
  
  if ($pass == $text) {
      session_register("user");
      header("location:admin.php");
  }
  
  else {
      include('form.php');
      echo "Invalid password: '$pass'";
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>How do I make the above code work as intended?</strong></p>