How can session_destroy() be used effectively to end a session in PHP?
To effectively end a session in PHP, you can use the session_destroy() function. This function destroys all data registered to a session and effectively ends the session. It is important to note that session_destroy() does not unset any session variables, so you may also want to use session_unset() to clear any session variables before calling session_destroy().
<?php
// Initialize the session
session_start();
// Unset all session variables
$_SESSION = array();
// Destroy the session
session_destroy();
?>