title: Simple PHP login with cookie
body: <p>I have begun developing this very simple PHP login that asks for a password to allow access to a website. It also creates a cookie to allow continued access until the user closes their browser window.</p>
  
  <p>At the top of each page I check for the cookie:</p>
  
  <pre><code>&lt;?php
  
      if(!isset($_COOKIE['authorised']) || ($_COOKIE['authorised'] != 'true'))
      {
          include('login.php'); exit;
      }
  
  ?&gt;
  </code></pre>
  
  <p>If they don't then I exit and show a login form:</p>
  
  <pre><code>&lt;?php
  
      function pageURL()
      {
          $pageURL = 'http';
          if ($_SERVER["HTTPS"] == "on")
          {
              $pageURL .= "s";
          }
          $pageURL .= "://";
          if ($_SERVER["SERVER_PORT"] != "80")
          {
              $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
          } 
          else
          {
              $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
          }
          return $pageURL;
      }
  
      $pageRedirect = pageURL();
  
      if(isset($_POST['password']) &amp;&amp; ($_POST['password'] == 'qwe123'))
      {
          setcookie('authorised', 'true'); header("Location:$pageRedirect",303);
      }
      else
      {
          include('noaccess.php'); exit;
      }
  
  ?&gt;
  &lt;form action="&lt;?php echo pageURL(); ?&gt;" method="post"&gt;
  &lt;input type="password" name="password" /&gt;
                  &lt;input type="submit" title="I agree" value="I agree" name="submit" /&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>The current PHP is from an old Warning page when you had to agree to access the site, I want to modify it to work with a simple form so that if the user types a password say for example 'qwe123' then they create the cookie and then are redirected back to the page but now have access because of the cookie. If they get it wrong then another page is included and exited.</p>
  
  <p>Can someone help me with this? Thanks</p>