Hermants
Hermants

Reputation: 241

Undefined index error: HTTP_REFERER in Chrome but not in 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?

Upvotes: 0

Views: 3714

Answers (1)

Alex
Alex

Reputation: 9265

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'] : '';

Upvotes: 4

Related Questions