Get Original Referrer URL from Google Search with PHP?

微笑、不失礼 提交于 2019-11-28 20:55:52

Google removes the search query for HTTPS connections and logged users so the only way to know the search query is using Google Analytics

When you search from https://www.google.com, websites you visit from our organic search listings will still know that you came from Google, but won't receive information about each individual query.

http://googleblog.blogspot.com.es/2011/10/making-search-more-secure.html http://analytics.blogspot.com.es/2011/10/making-search-more-secure-accessing.html

Try this.

parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $queries);

echo $queries['q'];

References:

http://php.net/parse_url

http://php.net/parse_str

$ref = $_SERVER['HTTP_REFERER'];
if(strstr($ref, "google.com")){
  //echo $ref;  
  $regex ='/q=(.+?)&/';
  preg_match($regex, $ref, $query);
  echo $query[1];
 }

it doesn't work everytime, especially now with their updates. I get " &esrc=s " reported a lot.

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