Sometimes you want to know what keywords have been used to find your site for some reason. A very handy script that will allow you to fetch these follows:

$referrer = $_SERVER['HTTP_REFERER'];
$str = "/[./](google|yahoo|bing|geegain|mywebsearch|ask|alltheweb).[a-z.]{2,5}[/]/i";
if(preg_match($str, $referrer, $search_engine)) {
    $referrer_query = parse_url($referrer);
    $referrer_query = $referrer_query["query"];
     //Yahoo uses both query strings use switch() for each search engine
    $q = "[q|p]";
    preg_match("/".$q."=(.*?)&/",$referrer,$keyword);
    $keyword = urldecode($keyword[1]);
   print $keyword;
}