title: How to destroy the session cookie correctly with PHP?
body: <p>I'm trying to correctly log out of an admin user. Here is my function:</p>
  
  <pre><code>function logout()
  {
      $_SESSION = array(); //destroy all of the session variables
      if (ini_get("session.use_cookies")) {
          $params = session_get_cookie_params();
          setcookie(session_name(), '', time() - 42000,
              $params["path"], $params["domain"],
              $params["secure"], $params["httponly"]
          );
      }
      session_destroy();
  }
  </code></pre>
  
  <p>Basically, once I authenticate the password, I set the session as being valid (only 1 user total). Now, when the admin hits logout, I want to destroy the current session, and also destroy the cookie, so that they can't just go back to the admin page using the stored session cookie in the browser. but my code doesn't work. i hit logout, and i can just directly navigate back to the admin page. however, if i delete my cookies, the functionality is perfect. so what's wrong with the cookie deleting function here?</p>