SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined index: HTTP_REFERER in /var/www/file.php

    Help me once more and I am done with my error log. The error is:

    Undefined index: HTTP_REFERER in /var/www/file.php

    ============ PHP CODE===============
    //get referer log
    if (!preg_match("/Mediapartners-Google/", $_SERVER['HTTP_USER_AGENT'])) {
    get_logs($_SERVER['HTTP_REFERER'], $_SERVER['REQUEST_URI'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
    }
    ===================================

    TIA.

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not all user agents will set this, it cannot really be trusted.
    my mobile portal
    ghiris.ro

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The question is not the User Agent. The question is PHP Notice: Undefined Index? What is meant by this?

    Thanks.

  4. #4
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BigResource View Post
    The question is not the User Agent. The question is PHP Notice: Undefined Index? What is meant by this?

    Thanks.
    It means there is an empty value for HTTP_REFERER. Not all browsers pass the referer. Notice message is not an error, its just a notice. If you dont want to see notices you can turn that off in your php.ini file.

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sillysoft View Post
    It means there is an empty value for HTTP_REFERER..
    It means the array key "HTTP_REFERER" is not set with in the array.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    It means the array key "HTTP_REFERER" is not set with in the array.
    Now come on, dont get technical with me in a php forum

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, now understand. I really appreciate if you can help with some alternative piece of code? I really need to log referer from Google only. Building sort of keyword list Google sending to me.

    Again thanks for any help you can offer me.

  8. #8
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a very simple version of what you're asking for

    PHP Code:
    if (stripos($_SERVER['HTTP_REFERER'], 'www.google.com')) {
        
    parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $qry);
        echo 
    $qry['q'];


  9. #9
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What happens if you place this above "//get referer log" ?

    Code:
    if( empty( $_SERVER['HTTP_REFERER']))
    {
        $_SERVER['HTTP_REFERER'] = getenv('HTTP_REFERER');
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •