What potential issues can arise when using $_SERVER['HTTP_REFERER'] to navigate pages in PHP?

Using $_SERVER['HTTP_REFERER'] to navigate pages in PHP can potentially lead to security vulnerabilities, as it relies on the client's browser to provide the referring URL, which can be easily manipulated. To avoid this issue, it is recommended to validate and sanitize the referring URL before using it for page navigation.

$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if (filter_var($referer, FILTER_VALIDATE_URL)) {
    header("Location: $referer");
    exit();
} else {
    // Handle invalid or malicious referer
}