How can a logout button in PHP be implemented to execute session_destroy() and redirect to a logout page?
To implement a logout button in PHP that executes session_destroy() and redirects to a logout page, you can create a logout.php file that contains the necessary code. When the user clicks on the logout button, it should redirect them to this logout.php file which will destroy the session and then redirect them to a logout success page.
<?php
session_start();
// Unset all session variables
$_SESSION = array();
// Destroy the session
session_destroy();
// Redirect to logout success page
header("Location: logout_success.php");
exit;
?>