Why does the alert window not display before the redirect to logout.php?

The issue is that the alert window is not displaying before the redirect because the redirect to logout.php is happening immediately after the alert is triggered. To solve this issue, you can delay the redirect by using JavaScript's setTimeout function after displaying the alert message.

<?php
// PHP code to display alert message before redirecting to logout.php

echo "<script>alert('You are about to logout.');</script>";
echo "<script>setTimeout(function(){ window.location.href = 'logout.php'; }, 3000);</script>"; // Redirect after 3 seconds
?>