How to get the referer search query from google?

拈花ヽ惹草 提交于 2019-12-18 04:03:02

问题


As recently as two days ago, the following code worked to get the search query from google:

$refer = parse_url($_SERVER['HTTP_REFERER']);
$host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$query = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY);

if(strstr($host,'www.google.com'))
{
    //do google stuff
    $qstart = strpos($query, 'q=') +2;
    $qend = strpos($query, '&', $qstart);
    $qlength = $qend - $qstart;
    $querystring = substr($query, $qstart, $qlength);
    $querystring = str_replace('q=','',$querystring);
    $keywords = explode('%20',$querystring);
    $keywords = implode(' ', $keywords);
    return $keywords;                      
    }

However, now it does not. I tested it by using echo($query) and it appears that the way google processes referrer query requests has changed. Previously $query included

"q=term1%20term2%20term3%20...

Now, however, I am getting the following output when $query is echo'ed:

sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CCsQFjAB&url=http%3A%2F%2Fexample.com%2F&ei=vDA-UNnxHuOjyAHlloGYCA&usg=AFQjCNEvzNXHULR0OvoPMPSWxIlB9-fmpg&sig2=iPinsBaCFuhCLGFf0JHAsQ

Is there a way to get around this?


回答1:


Sorry to say, but it's global Google politics change.

See web link

http://googlewebmastercentral.blogspot.ru/2012/03/upcoming-changes-in-googles-http.html

This means if user sign in Google account. You can try it yourself: if your Google search url starts with https:// this means Google will hide some scratch parameters for the sake of privacy.




回答2:


I too ran into the same issue this week. I'm not sure if this is still relevant to you, but what I found was that Google initiated SSL (Secure Sockets Layer) search for users who were signed in about a year ago, and it looks like SSL search may now be applied to all Google search queries. When I tested this, I was not signed in to Google and was using Firefox and still got the encrypted referring query.

This article has some helpful background and some ideas for working without specific search term data: http://searchenginewatch.com/article/2227114/5-Tips-for-Handling-Not-Provided-Data




回答3:


    // take the referer
$thereferer = strtolower($_SERVER['HTTP_REFERER']);
// see if it comes from google
if (strpos($thereferer,"google")) {
    // delete all before q=
    $a = substr($thereferer, strpos($thereferer,"q="));     
    // delete q=
    $a = substr($a,2);
    // delete all FROM the next & onwards
    if (strpos($a,"&")) {
        $a = substr($a, 0,strpos($a,"&"));
    }   
    // we have the results.
    $mygooglekeyword = urldecode($a);
}



回答4:


Google initiated SSL for all searches and the information is only available via Google Analytics. However, for paid campaigns search engines like Google, Bing and Yahoo use query string parameters such as utm_parameters and you can access the search query from the parameter utm_term.



来源:https://stackoverflow.com/questions/12181375/how-to-get-the-referer-search-query-from-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!