Is it necessary to destroy the session cookie in addition to calling session_destroy() when logging out a user in PHP, and why?

When logging out a user in PHP, it is not necessary to destroy the session cookie in addition to calling session_destroy(). However, destroying the session cookie can provide an extra layer of security by ensuring that even if the session data is somehow compromised, the cookie itself cannot be used to access the session. This can be especially useful in preventing session fixation attacks.

session_start();

// Unset all session values
$_SESSION = array();

// Destroy the session
session_destroy();

// Destroy the session cookie
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
}

// Redirect to login page or home page
header("Location: login.php");
exit();