admin管理员组文章数量:1404922
I want to make several uses of the search phrase that users used in google in order to reach my site.
Is there any programmatic way to do that?
Thanks, Oran
I want to make several uses of the search phrase that users used in google in order to reach my site.
Is there any programmatic way to do that?
Thanks, Oran
Share Improve this question asked Jan 28, 2012 at 21:34 OrPazOrPaz 1,08511 silver badges25 bronze badges 3- coding.pressbin./59/… – Brent Anderson Commented Jan 28, 2012 at 21:37
- Have you even tried anything? – random Commented Jan 28, 2012 at 21:55
- Sorry. Not yet. Will try and respond soon. – OrPaz Commented Feb 13, 2012 at 16:26
4 Answers
Reset to default 5You can use the code below:
$referrer = $_SERVER['HTTP_REFERER'];
if (!empty($referrer)) {
$parts_url = parse_url($referrer);
$query = isset($parts_url['query']) ? $parts_url['query'] : '');
if($query) {
parse_str($query, $parts_query);
$ref_keywords = isset($parts_query['q']) ? $parts_query['q'] : (isset($parts_query['query']) ? $parts_query['query'] : '' ));
}
}
However, note that Google has now stopped sending the query string in their referrer for all logged in users. So your functionality will work only for users who are logged out of Google . Here is more information on this http://googleblog.blogspot./2011/10/making-search-more-secure.html
Use the HTTP_REFERER
server variable.
$referer= $_SERVER['HTTP_REFERER'];
//find the search query from google that brought them here
$qref= strpos($referer,’google’);
if($qref!=”){
$qstart = strpos($referer,’q=’);
$qend = strpos($referer,’&’,$qstart);
$qtext= substr($referer,$qstart+2,$qend-$qstart-2);
$qtext= str_replace(‘+’,’ ‘,$qtext);
}
echo $qtext
Taken from here.
I reckon it should be in the referrer, as the they append the search string to the url via the q-parameter.
You can get it from the "HTTP_referer" in the request.($_SERVER['HTTP_REFERER'];)
see also another question regarding the topic
本文标签: phpCan I Get The Search Phrase From GoogleStack Overflow
版权声明:本文标题:php - Can I Get The Search Phrase From Google? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744865767a2629335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论