What is the purpose of session_destroy() in PHP and why is it not recommended for logging out users?

The purpose of session_destroy() in PHP is to destroy all data associated with the current session. However, it is not recommended for logging out users because it destroys all session data, including variables that may be needed for other functionality. Instead, it is better to unset specific session variables related to user authentication.

// Unset specific session variables for logging out users
session_start();
unset($_SESSION['user_id']);
unset($_SESSION['username']);
// Redirect to login page or home page
header("Location: login.php");
exit();