What potential issues could arise when redirecting URLs in PHP?

One potential issue that could arise when redirecting URLs in PHP is the possibility of causing an infinite redirect loop if the redirect logic is not properly implemented. To solve this issue, you can add a condition to check if the current URL is already the target of the redirect before performing the redirection.

// Check if the current URL is the target of the redirect
if ($_SERVER['REQUEST_URI'] != '/target-url') {
    header('Location: /target-url');
    exit;
}