How to disable PHP session cookie?

后端 未结 6 2164
醉梦人生
醉梦人生 2020-12-11 03:30

I am writing PHP code where I want to pass the session id myself using POST. I don\'t want a cookie to store the session, as it should get lost when the user gets out of the

6条回答
  •  青春惊慌失措
    2020-12-11 03:43

    If you just need to be able to zap a session at a given time, use session_destroy(). If you want to completely end the session, here's a snippet copy/pasted straight out of the documentation:

    // Initialize the session.
    // If you are using session_name("something"), don't forget it now!
    session_start();
    
    // Unset all of the session variables.
    $_SESSION = array();
    
    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (isset($_COOKIE[session_name()])) {
        setcookie(session_name(), '', time()-42000, '/');
    }
    
    // Finally, destroy the session.
    session_destroy();
    

提交回复
热议问题