Notice: Undefined index: HTTP_REFERER

前端 未结 4 1352
青春惊慌失措
青春惊慌失措 2020-12-15 18:30

Notice: Undefined index: HTTP_REFERER

$http_referer = $_SERVER[\'HTTP_REFERER\']

i used this from tutorial.and it looks okay

also code is calling it

相关标签:
4条回答
  • 2020-12-15 19:04

    HTTP_REFERER is not guaranteed to be sent by the client:

    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

    In your case it's clearly not being sent, so really all you can do is

    if(isset($_SERVER['HTTP_REFERER'])) {
      //do what you need to do here if it's set    
       }
    else
    {
       //it was not sent, perform your default actions here
    }
    
    0 讨论(0)
  • 2020-12-15 19:09

    The Correct way to reffer is

    $my_referer = isset($_POST['referer']) ? trim($_POST['referer']) : (isset($_SERVER['HTTP_REFERER']) ? base64_encode($_SERVER['HTTP_REFERER']) : false);
    
    0 讨论(0)
  • 2020-12-15 19:12
    if (isset($_SERVER['HTTP_REFERER'])) {$THE_REFER=$_SERVER['HTTP_REFERER']}
    
    0 讨论(0)
  • 2020-12-15 19:14

    Undefined index means the array key is not set, do a:

    var_dump($_POST); die(); 
    

    before the line that throws the error and see that you're trying to get an array key that does not exist.

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