View Full Version : Get Keyword Person Used on Google To Find Your Site
srule_
03-06-2008, 04:27 PM
Hey, This is a code that will store the keyword a person used on google to find your site:
<?php
// Get The URL and use parse_url to get an array of info about it
$url = parse_url($_SERVER['HTTP_REFERER']);
//If from Google Get query & Keywords
if ($url['host'] == 'www.google.com')
{
$query = $url['query'];
$param_array = explode('&',$query);
foreach ($param_array as $param)
{
if ($param{0} == 'q') // if first char is q, it's your google query.
{
$word_string = substr($param, 2); // strip 'q='
}
}
$word_string = str_replace('"', '', urldecode($word_string));
$words = explode(' ', $word_string);
echo "<pre>\n";
print_r($words);
echo "</pre>\n";
} else //If not from google tell them so
{
echo "you are not coming from google";
}
?>
if their is a better way to do this please inform me! Main problem with this is that if person did not use google.com (ie: google.ca or somthing) then the script does not think they are from google.
oesxyl
03-06-2008, 05:20 PM
if their is a better way to do this please inform me! Main problem with this is that if person did not use google.com (ie: google.ca or somthing) then the script does not think they are from google.
yes, is a better way. The main problem here is the idea, your content must have the proper title, not a title generated by users random search. You probably expect to increase relevance but in fact will not, trust me.:)
This problem is not solved at the level of se and they don't expect to find a solution, at least, few years from now. :)
About the script, don't work in more many situation, google have many domains not only com and ca, work with ip not only with dns and also for mobile, and this is only about google. We don't talk about other two major se Yahoo and MSN and also we don't talk about not having referer.
We don't talk also about the fact that making this to work will increase the page loading time and this will decrease the number of visitors.
Seems stupid but the content with the proper title is the single thing that works.
Sorry that I dissipoint you
best regards
srule_
03-07-2008, 02:51 PM
Good points, will this effect SEO too? Like when a googlebot crawls a site with this code what would they see?
oesxyl
03-07-2008, 09:57 PM
Good points, will this effect SEO too? Like when a googlebot crawls a site with this code what would they see?
because bot see something else then users, this is cloaking, a old trick of blakhat seo. People can say that google penalize you for that few month, half year or more, :)
I think that google will try to restore the search relevance and this is a slow process.
best regards
demtron
01-25-2009, 04:25 PM
At one time, I remember seeing a site that posted referred parsing code for Google, Yahoo and MSN URLs. It included ASP.Net code, but it would probably be easily adaptable to PHP. I will look this morning and post it here if I can find it. I want to say that it was at codeproject.com.
Rohan_Shenoy
01-28-2009, 06:12 PM
Better code:
<?php
$parsed_url=parse_url($_SERVER['HTTP_REFERER']);
if(stripos($parsed_url['host'],'google'))
{
parse_str($parsed_url['query'],$parsed_query_string);
$keyword_string=$parsed_query_string['q'];
$keyword_string=explode('',$keyword_string);
}
?>
Rohan_Shenoy
01-28-2009, 06:12 PM
Better code:
<?php
$parsed_url=parse_url($_SERVER['HTTP_REFERER']);
if(stripos($parsed_url['host'],'google'))
{
parse_str($parsed_url['query'],$parsed_query_string);
$keyword_string=$parsed_query_string['q'];
$keyword_string=explode('',$keyword_string);
}
?>
RedMatrix
04-04-2009, 09:51 PM
The exploded string returns "Array", literally.
This works:
<?php
$parsed_url=parse_url($_SERVER['HTTP_REFERER']);
if(stripos($parsed_url['host'],'google'))
{
parse_str($parsed_url['query'],$parsed_query_string);
$keyword_string=$parsed_query_string['q'];
}
?>
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.