PHP Notice: Undefined index: HTTP_REFERER Error

Discussion in 'PHP' started by Entrep, Jul 31, 2011.

  1. #1
    I keep getting these errors in my log files:

    [Sun Jul 31 05:50:04 2011] [error] [client xxxxxxxxxx] PHP Notice: Undefined index: HTTP_REFERER in /home/webadmin/xxxxxxxxxxx.com/html/include/common.php on line 491

    Line 491 is a line that (I think) records someones IP when they submit an article to the site:

    $l_sReferer = isset($_POST['referer']) ? trim($_POST['referer']) : base64_encode($_SERVER['HTTP_REFERER']);

    Can anyone tell me how to fix this error?

    Cheers
     
    Entrep, Jul 31, 2011 IP
  2. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #2
    Well, it's not an error just a notice. It seems that $_SERVER['HTTP_REFERER'] is undefined. You can change the line:

    $l_sReferer = isset($_POST['referer']) ? trim($_POST['referer']) : (isset($_SERVER['HTTP_REFERER']) ? base64_encode($_SERVER['HTTP_REFERER']) : false);
    PHP:
    This way it checks whether HTTP_REFERER is set and if it is not, returns false.
     
    bogi, Jul 31, 2011 IP
  3. Entrep

    Entrep Well-Known Member

    Messages:
    588
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Cheers thanks for that
     
    Entrep, Aug 1, 2011 IP