title: PHP Session Destroy
body: <p>How do I destroy a session in php? </p>
  
  <p>the thing is when the user clicks the logout button the session will end and he will be redirected to the index.php here's my code</p>
  
  <p>Customer.php</p>
  
  <pre><code>&lt;?php 
  
  session_start(); 
  #include("Connection.php");
  if (isset($_POST['submit'])) { 
  $name = $_POST['customerName']; 
  $_SESSION['user'] = $name; 
  } 
  if (isset($_SESSION['user'])) { echo "Hello {$_SESSION['user']}, welcome back"; }
  else{echo "walang tao";}
  
  $sql="INSERT INTO ORDERS(Name) VALUES('$name')";
  mysql_query($sql);
  
  session_destroy();
  ?&gt;
  &lt;button&gt;&lt;a href="Customer.php"&gt;&lt;/a&gt;&lt;/button&gt;
  </code></pre>
  
  <p>and this is from the index.php where the user wants to log in again</p>
  
  <pre><code>&lt;?PHP 
  /* this must go before any html */ 
  session_start(); 
  
  if (isset($_SESSION['user'])) { 
  header("location: Customer.php"); 
  } 
  ?&gt; 
       &lt;div class="sign"&gt;
                      &lt;h2&gt;Welcome&lt;/h2&gt;
                      &lt;form action = "Customer.php" method = "POST"&gt;
                      Customer Name:&lt;input type = "text" name="customerName"&gt;
                      &lt;input type = "submit" name = "submit"&gt;
                      &lt;/form&gt; 
  </code></pre>