未定义的索引错误:Chrome中的HTTP_REFERER,但FireFox中没有

To get the right htpp/https + domain name I use $_SERVER['HTTP_REFERER']. It works well in FF but in Chrome I get the error: Undefined index: HTTP_REFERER

I can solve this simple to include next line in the code above by declaring

$_SERVER['HTTP_REFERER'] = '';

But I find it strange that this erros appears in Chrome. Or do I have to declare always $_SERVER[''] at the beginning of the function?

Just check if it is set. Simply:

if (isset($_SERVER['HTTP_REFERER'])) {
   $referer = $_SERVER['HTTP_REFERER'];
} else {
   $referer = '';
}

or $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';