PHP Google Referrer Keyword Phrase

This is a PHP snippet, talking about google, keyword and referer

PHP Google Referrer Keyword Phrase Add to Favorite

// take the referer
$thereferer = strtolower($_SERVER['HTTP_REFERER']);
// see if it comes from google
if (strpos($thereferer,"google")) {
	// delete all before q=
    $a = substr($thereferer, strpos($thereferer,"q="));		
	// delete q=
	$a = substr($a,2);
	// delete all FROM the next & onwards
	if (strpos($a,"&")) {
		$a = substr($a, 0,strpos($a,"&"));
	}	
	// we have the results.
	$mygooglekeyword = urldecode($a);
}

Sometimes it can be useful to know why a visitor arrived on a certain page. For instance, if you have a FAQ page on a variety of topics, you could provide a quick menu related to the terms that the user is interested in, before the remainder of the page. Alternatively, you could rewrite the page so that the terms are highlighted or indeed redirect the user to a more specific page altogether.

I wrote the following exert as part of a larger script that provided search results for pages that had a low match to the keyterm in the main content.

Certain pages on a website were getting referrals because of navigational links to other pages, so people where hitting the 'widget' page, when they had really wanted the 'thingy' page because the original widget page mentioned and linked to the 'thingy' page. With this as a plug-in on the page, we could help provide a more appropriate page and a better user experience for our visitors.

Created by ThePeppersStudio (349 days, 8.57 hours ago)

Do you want to leave a message? Please login first.