How can the PHP script be improved to prevent an endless redirect loop?

The issue of an endless redirect loop can be solved by adding a condition to check if the current page is already the redirect destination before performing the redirect. This prevents the script from continuously redirecting to the same page.

<?php
$redirectDestination = "destination.php";

if ($_SERVER['REQUEST_URI'] != $redirectDestination) {
    header("Location: $redirectDestination");
    exit();
} else {
    echo "Already at the redirect destination.";
}
?>