How can one ensure that a session is destroyed when the browser is closed in PHP?
To ensure that a session is destroyed when the browser is closed in PHP, you can set the session cookie to be a session cookie by specifying a lifetime of 0. This way, the session cookie will expire when the browser is closed, effectively destroying the session.
// Start the session
session_start();
// Set the session cookie to be a session cookie
session_set_cookie_params(0);
// Destroy the session
session_destroy();
            
        Related Questions
- What considerations should be taken into account when planning the architecture of a PHP forum for easy scalability and maintenance?
 - What are the best practices for handling user input from email forms in PHP to ensure security and accuracy?
 - How can the "Strict Standards: Only variables should be passed by reference" error be resolved in PHP?