Result from $_SERVER['HTTP_REFERER'], when referer header is not sent to server

前端 未结 3 1966
独厮守ぢ
独厮守ぢ 2021-01-04 03:58

When the browser sends header info to the server, $_SERVER[\'HTTP_REFERER\'] should give us the previous page URL right?

What returns from $_SERVE

相关标签:
3条回答
  • 2021-01-04 04:46

    If the HTTP referer request header is not sent then the $_SERVER['HTTP_REFERER'] is probably not set, although it could be an empty string. Whether it is set or not in this case could depend on the server.

    As with all HTTP request headers, check for its existence when reading:

    $httpReferer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
    
    0 讨论(0)
  • 2021-01-04 04:49

    $_SERVER['HTTP_REFERER'] is not really reliable because particular setting on the user browser could break it. But yes it should contain the previous URL and it will return empty string or NULL when headers are not sent, depending on the server configuration.

    0 讨论(0)
  • 2021-01-04 04:56

    $_SERVER is a global array variable, and the referrer value is an element of the array with key HTTP_REFERER. If is no referrer header is sent by the browser, then the element is simply missing from the array. You can check whether an array has an element with array_key_exists; in this case:

    array_key_exists('HTTP_REFERER', $_SERVER)

    0 讨论(0)
提交回复
热议问题