How to check if a visitor came from a search engine?

Discussion in 'PHP' started by Lafaso870, May 13, 2011.

  1. #1
    I would like to slightly change the content of a page if a user came from a search engine, as opposed to an email/blog/forum/etc link.

    How should I go about doing this?

    Thanks
     
    Lafaso870, May 13, 2011 IP
  2. fouzan

    fouzan Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could try google analytics for this, but before that you have to install the code on your website check website here

    http://www.google.com/analytics/

    hope this helped you :)
     
    fouzan, May 13, 2011 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    There's no guaranteed way to do this. You can look at the HTTP_REFERER variable but it is optionally set by browser. There could be as many as 30% of visitors who's browsers don't set the variable.

    If you have any control over the links on other blogs / email, etc. you could append a variable to the url, mysite.com?source=email. You could then easily look for this variable when a visitor arrives.
     
    jestep, May 13, 2011 IP
  4. JoelLarson

    JoelLarson Peon

    Messages:
    61
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Strangely enough, I had a talk with a mate that wanted to do something similar to this on a larger scale. This is what I recommended:

    $_SERVER['HTTP_REFERRER'] is going to be your best solution for this, even though it's not completely dependable. You can create a list of popular search engine URLs by visiting a site like: http://www.thesearchenginelist.com/

    Then, you parse the $_SERVER['HTTP_REFERRER'] to get the hostname out of it. From here, compare the hostname to the hostname from the search engine list that you have. If it's in the list of hostnames, show the changed content.
     
    JoelLarson, May 13, 2011 IP