Return to Snippet

Revision: 7943
at August 23, 2008 08:09 by jamesming


Initial Code
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;
}

Initial URL
http://www.webmasterworld.com/forum88/10984.htm

Initial Description


Initial Title
Which Search Engine is referring users to your site.  Displays the keyword used.

Initial Tags
google

Initial Language
PHP