title: Logout when using cookies
body: <p>I am beginner in using php cookies and I am trying to make a simple login and logout form using cookies. everything was good but when I press logout link I can't logout. and to logout I have to delete the cookies from the browser.</p>
  
  <p>log_in page</p>
  
  <pre><code>&lt;?php
  session_start();
  
  if (isset($_COOKIE["Email"])){
      header("location: home.php");    
  }
  ?&gt;
  
  
  &lt;form method="post" action="log_in.php"&gt;   
  &lt;font size="6"&gt;Sign In&lt;/font&gt;
  
  Email Address: &lt;/b&gt;&lt;/font&gt;&lt;input type="text" name="Email" id="email"  /&gt;  
  
  password:  &lt;input type="password" name="password" id="password"  /&gt;    
  
  &lt;input type="checkbox" name="rememberMe" value="1" id="check"/&gt; Remember Me
  
  &lt;input type="submit" name="Login" id="sign" value="sign in" &gt;
  
  &lt;?php 
  include 'db.php';
  if(isset($_POST['Login'])){
      $user_email = $_POST['Email'];  
      $password = $_POST['password'];
  
      $check_user = "SELECT * FROM user where user_email  = '$user_email' AND user_pass = '$password'";
      $run = mysql_query($check_user );
  
      if (mysql_num_rows($run) &gt; 0){
          $_SESSION['Email']= $user_email;   
  
          $_SESSION['start'] = time(); 
          if(isset($_POST['rememberMe'])){
              $expire=time()+120;
              setcookie("Email", "Email", $expire);
          }
      else{
          $expire=time()+30;
          setcookie("Email", "Email", $expire);
      }
      echo "&lt;script&gt;window.open('home.php','_self')&lt;/script&gt;";   
  }
  else {
      echo "&lt;script&gt;alert('email or password incorrect!')&lt;/script&gt;";     
  }}
  ?&gt;
  </code></pre>
  
  <p>home page</p>
  
  <pre><code>&lt;?php
  if (isset($_COOKIE["Email"])){
    echo "Welcome " . $_COOKIE["Email"] . "!&lt;br&gt;";
      echo '&lt;a href="logoutForm.php"&gt;logout&lt;/a&gt;';
  }
  else{
      $now = time(); // Checking the time now when home page starts.
      if ($now &gt; $expire) {
          session_destroy();
          header("location: log_in.php");    
  }}
  </code></pre>
  
  <p>logout page</p>
  
  <pre><code> &lt;?php
   session_start();
   unset($_SESSION['Email']);
   session_destroy();
   header("Location: log_in.php");
  
   if(isset($_SESSION['Email'])):
       setcookie($_SESSION['Email'],'',time()-7000000,'/');
   endif;
   ?&gt;
  </code></pre>