how do you detect if your website visitor came from a google search result?

前端 未结 6 466
粉色の甜心
粉色の甜心 2020-12-03 16:06

when a user searches from google and lands on our site from the results he/she was shown in the results page, is there a way for my site to detect that he came from google?<

相关标签:
6条回答
  • 2020-12-03 16:38

    Check the $_SERVER['HTTP_REFERER'] variable which should contain the referring URL. Please note that this is not tamper-proof or fail-safe as the Http-Referer header can easily been changed or modified by a client.

    EDIT: Just googled for phpinfo (because chanes were high that I get a phpinfo() page that shows the $_SERVER['HTTP_REFERER'] variable) to show you how the Http-Referer will look like:

    $_SERVER['HTTP_REFERER'] = "http://www.google.de/search?hl=de&q=phpinfo&btnG=Google-Suche&meta="
    

    As you see, you can also extract the search term used in the google query (or detect if the search was initiated by the Google Chrome address bar)...

    0 讨论(0)
  • 2020-12-03 16:38

    It looks like you can use the $_SERVER['HTTP_REFERER'] variable. But I think the value is controlled by the client and can't always be guaranteed to exist or accurate.

    0 讨论(0)
  • 2020-12-03 16:44

    HTTP_REFERER : Returns a string containing the URL of the page that referred the request to the current page using an tag. If the page is redirected, HTTP_REFERER is empty.

    Using HTTP_REFERER used for ASP.

    0 讨论(0)
  • 2020-12-03 16:50

    Check referrer of a request. It should contain www.google.com/...

    0 讨论(0)
  • 2020-12-03 16:52

    You would check the $_SERVER['HTTP_REFERER'] if you wanted to do it in PHP. You can also use document.referrer in javascript.

    0 讨论(0)
  • 2020-12-03 16:53

    Yes, use the HTTP_ REFERER var in the $_SERVER array:

    $_SERVER['HTTP_REFERER'];
    

    This shoudl then include something like http://www.google.com/?q=etc

    Note however that the REFERER is not always set because clients can disable their browser to send it in the request.

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