Kenneth,
$HTTP_REFERER is set by your browser, and is optional. If your browser supports sending this HTTP header, then it the only instance it should not send one is if the request is sent from a source that does not have its own URI.
If this code is essential, you should pass it as an argument to prevent possible mistakes.
Can you post the code here?
Regards,
David Grant