Catch keywords from Google with PHP script

Try this for catch keywords at your web


function get_search_phrase($referer){

$key_start = 0;
$search_phrase = “”;

// used by google, msn, alta vista, ask jeeves, all the web, teoma, wisenut, search.com
if (strpos($referer, ‘q=’) !== false) $key_start = strpos($referer, ‘q=’) + 2;

// if present, get the search phrase from the referer
if ($key_start > 0){
if (strpos($referer, ‘&’, $key_start) !== false){
$search_phrase = substr($referer, $key_start, (strpos($referer, ‘&’, $key_start) - $key_start));
} else {
$search_phrase = substr($referer, $key_start);
}
}

$search_phrase = urldecode($search_phrase);
return $search_phrase;

} // end get_search_phrase

$keyword = get_search_phrase($_SERVER["HTTP_REFERER"]);

Related Posts:

Tags: , ,

03.Oct.08 PHP


You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Reader's Comments

  1. Butterfly | October 29th, 2008 at 8:20 am

    Keep up the good work.

Leave a Comment

:)