Capture search engine keywords in php

后端 未结 2 682
孤独总比滥情好
孤独总比滥情好 2021-01-24 13:22

In awstats I get a table with all the key words and phrases used to find my website. I would like to capture this myself however each search engine url is in a different format

相关标签:
2条回答
  • 2021-01-24 13:41

    One possibility is to just grab the referring URL ($_SERVER['HTTP_REFERER']) and parse out the keywords in it.

    For example, check out this Google URL (searching for "stack overflow"):

    http://www.google.com/search?hl=en&q=stack+overflow&aq=0&oq=stack+over&aqi=g10
    

    The value of the q GET variable holds the keywords delimited by + signs.

    0 讨论(0)
  • 2021-01-24 13:52

    I am having to add to it all the time, but here is a REGEX that should strip out the keywords from google, yahoo, bing, ask, and MSN (same as Bing). It leaves the + in between, but it should be a good place for you to start:

    .*(\?p=|\?q=|&q=|\?s=)([a-zA-Z0-9 +]*)(&toggle=|&ie=utf-8|&FORM=|&aq=|&x=|&gwp).
    
    0 讨论(0)
提交回复
热议问题