title: How to logout a user in php?
body: <p>I am making a login system and I just got it to work, and now I am having difficulty making a logout feature for my website. Its not actually hosted yet, so security will come later. I have tried various uses of session_destroy and unset, but i cannot get it to work. Any help would be appreciated.</p>
  
  <p>My PHP</p>
  
  <pre><code>&lt;?php
  session_start();
  /*This is the equivalent of login.php*/
  $database = "forum";  // the name of the database.
  $server = "localhost";  // server to connect to.
  $db_user = "root";  // mysql username to access the database with.
  $db_pass = "";  // mysql password to access the database with.
  $table = "members";    // the table that this script will set up and use.
  $link = mysql_connect($server, $db_user, $db_pass);
  mysql_select_db($database,$link);
  
  if (isset($_POST['fsubmitted'])) {
  // Get the data passed from the form
  $username = $_POST['username'];
  $pass = $_POST['pass'];
  
  // Do some basic sanitizing
  $username = stripslashes($username);
  $pass = stripslashes($pass);
  $encryptedpass = md5($pass);
  
  $sql = "SELECT * from members where username = '$username' and password = '$encryptedpass'";
  $result = mysql_query($sql);
  
  
  $count = 0;
  
  $count = mysql_num_rows($result);
  
  if ($count == 1) {
       $_SESSION['loggedIn'] = "true";
      header("Location: index.php"); // This is wherever you want to redirect the user to
      exit();
  
  } else {
       $_SESSION['loggedIn'] = "false";
       echo '&lt;div class="errormsgbox"&gt;Your username and password combo was incorrect!&lt;/div&gt;';
       var_dump($result);
      echo $sql;
  }
  }
  
  if ($_SESSION['loggedIn'] = "true") {
      echo '&lt;div class="success"&gt;You are now logged in!&lt;/div&gt;';
  }
  
  if (isset($_SESSION['loggedin']) &amp;&amp; (time() - $_SESSION['loggedin'] &gt; 1800)) {
      // last request was more than 30 minutes ago
      session_unset();     // unset $_SESSION variable for the run-time 
      session_destroy();   // destroy session data in storage
  }
  $_SESSION['loggedin'] = time(); // update last activity time stamp
  
  ?&gt;
  </code></pre>