if ((isset($_SERVER['HTTP_REFERER'])) and ($_SERVER['HTTP_REFERER']!= '')) {
$keywords = "";
$url = urldecode($_SERVER['HTTP_REFERER']);
// Google
if (eregi("www.google",$url)) {
preg_match("'(?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'Google';
}
// Yahoo
if ((eregi("yahoo.com",$url)) or (eregi("search.yahoo",$url))) {
preg_match("'(?¦&)p=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'Yahoo';
}
// MSN
if (eregi("search.msn",$url)) {
preg_match("'(?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'MSN';
}
// AllTheWeb
if (eregi("www.alltheweb",$url)) {
preg_match("'(?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'AllTheWeb';
}
// Looksmart
if (eregi("looksmart.com",$url)) {
preg_match("'(?¦&)qt=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'Looksmart';
}
if (($keywords[2]!= '') and ($keywords[2]!= ' ')) {
$keywords = preg_replace('/"¦'/', '', $keywords[2]); // Remove quotes
}
echo $keywords;
echo $search_engine;
}
source