title: add logout to password protect page
body: <p>I have a page I want to password-protect. I've tried the code below, but I am unable to put logout to the page. Any other quick (and easy) way to do this? Thanks!</p>
  
  <p>How I can add logout to this password protected page as described below</p>
  
  <pre><code>$username = "the_username_here";
  $password = "the_password_here";
  $nonsense = "supercalifragilisticexpialidocious";
  
  if (isset($_COOKIE['PrivatePageLogin'])) {
  if ($_COOKIE['PrivatePageLogin'] == md5($password.$nonsense)) {
  
  
  LOGGED IN CONTENT HERE
  
    exit;
  } else {
    echo "Bad Cookie.";
    exit;
  }
  }
  
  if (isset($_GET['p']) &amp;&amp; $_GET['p'] == "login") {
  if ($_POST['user'] != $username) {
    echo "Sorry, that username does not match.";
    exit;
   } else if ($_POST['keypass'] != $password) {
    echo "Sorry, that password does not match.";
    exit;
   } else if ($_POST['user'] == $username &amp;&amp; $_POST['keypass'] == $password) {
    setcookie('PrivatePageLogin', md5($_POST['keypass'].$nonsense));
    header("Location: $_SERVER[PHP_SELF]");
   } else {
    echo "Sorry, you could not be logged in at this time.";
  }
  }
  </code></pre>
  
  <p>And the login form on the page...</p>
  
  <pre><code>&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;?p=login" method="post"&gt;
  &lt;label&gt;&lt;input type="text" name="user" id="user" /&gt; Name&lt;/label&gt;&lt;br /&gt;
  &lt;label&gt;&lt;input type="password" name="keypass" id="keypass" /&gt; Password&lt;/label&gt;&lt;br /&gt;
  &lt;input type="submit" id="submit" value="Login" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Any clue on how to get this solved ?</p>