Topics

Get Keyword from referrer

This Function should extract the keyword from the referrer URL to get what your visitor was searching for on google, msn, live, altavista, alltheweb, scirus, aol, vivisimo, lycos, aliweb, yahoo and baidu.

function getKeywordfromRef($orgWord){
	$ref = $_SERVER['HTTP_REFERER'];
	if( preg_match("#(google|msn|live|altavista|alltheweb|scirus)#", $ref)){
		$s=explode("?",$ref);
		parse_str($s[1]);
		return $q;
	}elseif(preg_match("#(aol|vivisimo|lycos|aliweb)#", $ref) ){
		$s=explode("?",$ref);
		parse_str($s[1]);
		return $query;
	}elseif(strstr( $ref,'yahoo')){
		$s=explode("?",$ref);
		parse_str($s[1]);
		return $p;
	}elseif(strstr( $ref,'baidu')){
		$s=explode("?",$ref);
		parse_str($s[1]);
		return $wd;
	}else
		return $orgWord;
}

you can send a default keyword in case the visitor was not coming from a search engine or just set $orgWord = ”
to call the function

$myKeyword = getKeywordfromRef($myKeyword)