Why might the $HTTP_REFERER variable be empty on certain pages when the script is included?

The $HTTP_REFERER variable may be empty on certain pages when the script is included because the referring page may not be sending the HTTP_REFERER header. This can happen if the user navigated directly to the page or if the referring page is on a different domain. To solve this issue, you can check if the $HTTP_REFERER variable is empty and handle it accordingly in your PHP script.

if(empty($_SERVER['HTTP_REFERER'])) {
    // Handle the case when HTTP_REFERER is empty
} else {
    $referer = $_SERVER['HTTP_REFERER'];
    // Use the $referer variable in your script
}