Get Original Referrer URL from Google Search with PHP?

♀尐吖头ヾ 提交于 2019-11-27 13:19:21

问题


I am using $_SERVER['HTTP_REFERER'];, to getting Referrer URL.

When I typed in Google search box the q='some text'

`https://www.google.com.pk/#hl=en&output=search&sclient=psy-ab&q=some text%2Ftestbulkresponse&oq=some text%2Ftestbulkresponse&gs_l=hp.3...15460.24280.1.25007.30.30.0.0.0.0.325.7136.2-27j3.30.0...0.0...1c.1.8.hp.dAvuch3bBg4&psj=1&bav=on.2,or.r_qf.&bvm=bv.44697112,d.ZWU&fp=980e418276b62e8c&biw=1366&bih=595`

but when I get this URL on my website using as $_SERVER['HTTP_REFERER'];

the q=null like this

`http://www.google.com.pk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CC0QFjAA&url=http%3A%2F%2Fwww.bulkresponse.com%2Ftestbulkresponse%2Fdashboard.php&ei=r9NbUfv7GcjaOYDdgKgC&usg=AFQjCNF9U_DpJEwupZ0ZLPbjWJ6DQLWZcA&bvm=bv.44697112,d.ZWU`. 

So I am unable to get searched keywords in Google, what should I can do to get searched keywords?


回答1:


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




回答2:


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




回答3:


$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.



来源:https://stackoverflow.com/questions/15781034/get-original-referrer-url-from-google-search-with-php

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