What could be causing the redirection in the else loop to execute even though it should not be possible in PHP?

The issue could be caused by a logical error in the condition check of the if statement, leading to the redirection in the else loop being executed when it should not. To solve this issue, double-check the condition in the if statement to ensure it is evaluating correctly.

<?php
// Incorrect condition check causing redirection in else loop to execute
$condition = false;

if ($condition == true) {
    header("Location: page1.php");
    exit();
} else {
    header("Location: page2.php");
    exit();
}
?>