Copy the code below:
<?php
session_start();
// Unset all session variables
$_SESSION = [];
// Destroy the session
session_destroy();
// Redirect to index.php with a logout message
header("Location: index.php?message=loggedout");
exit;
?>