0

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?

Hermants
  • 231
  • 1
  • 3
  • 9
  • 2
    This simply means that the Chrome web browser did not send a referer. If none is specified, then PHP cannot present one. That has nothing to do with PHP. You will have to specify the precise situation where this different behavior of browsers can be shown. – arkascha Sep 30 '16 at 12:49
  • http://stackoverflow.com/a/12369682/4248328 – Alive to die - Anant Sep 30 '16 at 12:50
  • 2
    Possible duplicate of [$\_SERVER\['HTTP\_REFERER'\] missing](http://stackoverflow.com/questions/12369615/serverhttp-referer-missing) – Alive to die - Anant Sep 30 '16 at 12:51
  • So this means that my solution is correct: add declaration of $_SERVER['HTTP_REFERER'] above the call of $_SERVER['HTTP_REFERER']. – Hermants Sep 30 '16 at 12:55

1 Answers1

4

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

Alex
  • 9,215
  • 8
  • 39
  • 82