title: Simple Logout Script
body: <p>I'm using the code below to log users in. When the new session is created they are redirected to a new page - <code>content.php</code>. I wonder what's the best way/the proper way to destroy the session and log out the users, redirectiong them back to the <code>index.php</code>.</p>
  
  <pre><code>&lt;?php 
  if (isset($_REQUEST['signin'])){
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  $query = "SELECT * FROM `user` WHERE username='$username' and password='$password'";
  $result = mysql_query($query) or die(mysql_error());
  $count = mysql_num_rows($result);
  
  if ($count == 1){
  $_SESSION['username'] = $username;
  header('Location: content.php');
  }
  else{
  echo "Invalid Login Credentials.";
  }
  }
  if (isset($_SESSION['username'])){
  $username = $_SESSION['username'];
  header('Location: content.php');
  }
  ?&gt;
  
  
  &lt;form method="post" name="login"&gt;
          &lt;?php 
          if (isset($msg) &amp; !empty($msg)) {
                      echo $msg;
                      }
          ?&gt;
          &lt;label for="username"&gt;Username:&lt;/label&gt;&lt;br&gt;
          &lt;input type="text" name="username"&gt;&lt;br&gt;
          &lt;label for="password"&gt;Password:&lt;/label&gt;&lt;br&gt;
          &lt;input type="password" name="password"&gt;&lt;br&gt;
          &lt;button type="submit" name="signin"&gt;Sign in&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I know that there are flaws in this script (e.g. not encrypted password), but for now I'm looking for a simple script to log out.</p>