if you do preg_match on $_SERVER['HTTP_REFERER'] to see whether its from google, then get the q= part, thats the search terms, you could then mail it to yourself ot add to a database. Heres the script that I use (in the head of a every page)
PHP Code:
function referer()
{
$parts=parse_url($_SERVER['HTTP_REFERER']);
if(strstr($parts['host'],"google")) { //if they've come from google
$get=preg_split("#&#",$parts['query']); //get query string of url
foreach($get as $key=>$stuff) { //put into an array of var=value
$data=preg_split("#=#",$stuff);
$get[$data[0]]=$data[1];
unset($get[$key]);
}
if($get['q']) { //if q= was in the query string
$search_phrase=$get['q']; //thats the search terms
if($get['start']) { //if start was set, that indicates what page they ame from
$page=($get['start']/10)+1;
} else {
$page=1; //..otherwise it was page 1
}
$entry_page=$_SERVER['PHP_SELF']; //mark what page they came in on
$query="INSERT INTO google_terms VALUES('".$search_phrase."', '".$page."', '".$entry_page."')";
@mysql_query($query); //put into database
}
}
}
Bookmarks