Search engine keywords extraction
By Romain Tuesday, January 29 2008 - 10:24 UTC - Tech - Permalink
By Romain Tuesday, January 29 2008 - 10:24 UTC - Tech - Permalink
For fuckthespam!, I wanted to add a nice feature due to the content of this website: a listing of keywords that people used to come on this website.
Well, the code is pretty simple bust just wanted to share it; it's working for google, msn and yahoo (the 3 most important search engine), I don't really care about having everything and just wanted to share this PHP snippet.
$referer = $_SERVER["HTTP_REFERER"];
if (strpos($referer,"search") > 0) {
// look for google, yahoo and MSN
$key = 0;
if (strpos($referer,"google.") > 0 || strpos($referer,"msn.") > 0)
$key = "q";
else if (strpos($referer,"yahoo.") > 0)
$key = "p";
if ($key) {
$parse_url = parse_url (urldecode($referer));
if (array_key_exists("query",$parse_url)) {
$query = $parse_url['query'];
// extract (.+)$key=(.*)&
$t = explode("&", $query);
foreach($t as $k=>$e) {
if ($e[0] == $key && $e[1] == '=') {
$k = "$key=";
$keyword = str_replace($k,'',$e);
if (strlen($keyword) > 2) {
// $keyword is actually the whole content of the search
}
break;
}
}
}
}
}
Comments
thanks you but has a problem.