PHP Notice: Undefined index: HTTP_REFERER Error

I keep getting these errors in my log files:

[Sun Jul 31 05:50:04 2011] [error] [client xxxxxxxxxx] PHP Notice: Undefined index: HTTP_REFERER in /home/webadmin/xxxxxxxxxxx.com/html/include/common.php on line 491

Line 491 is a line that (I think) records someones IP when they submit an article to the site:

$l_sReferer = isset($_POST[‘referer’]) ? trim($_POST[‘referer’]) : base64_encode($_SERVER[‘HTTP_REFERER’]);

Can anyone tell me how to fix this error?

Cheers

the HTTP_REFERER. Yes. Always the very worst thing to rely upon. Never, ever rely on it. Ever.

I’d shard it out and put a secondary check in there.


if(isset($_POST['referer'])) {
  $l_sReferer = trim($_POST['referer']);
} elseif (isset($_SERVER['HTTP_REFERER'])) {
  $l_sReferer = base64_encode($_SERVER['HTTP_REFERER']);
} else {
  $l_sReferer = "";
}

Cheers thank you - I just replaced the entire line with the code above and it seems to be working.