What are some common errors that can lead to a redirection loop in PHP code?

A common error that can lead to a redirection loop in PHP code is forgetting to check if the current page is the one being redirected to. This can happen when using a header redirect without checking the current URL before redirecting. To prevent a redirection loop, you should always check if the current page is the same as the one you are redirecting to before performing the redirect.

// Check if the current page is the one being redirected to
if ($_SERVER['REQUEST_URI'] != '/redirected-page.php') {
    // Redirect to the desired page
    header('Location: /redirected-page.php');
    exit();
}