Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

php - How to get the referer search query from google?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...