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)#si", $ref)){
		$s=explode("?",$ref);
		parse_str($s[1]);
		return $q;
	}elseif(preg_match("#(aol|vivisimo|lycos|aliweb)#si", $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)

Recommended posts:


Tags : si

This entry was posted on Sunday, November 26th, 2006 at 5:09 am and is filed under Blog, Solutions. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


 Top