[thelist] get google keywords with PHP

Damien COLA damiencola at wanadoo.fr
Mon Feb 2 20:27:19 CST 2004


<tip type="Backend PHP" author="Damien COLA">
Google sends many visitors to your site, if you want to get the keywords
they used to come to your site, maybe to impress them by displaying it
back on the page, or just to store the keyword in a database, here's the
PHP code I use :

// 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);
}

and we can use <?= $mygooglekeywords ?> when we want to output the
keywords.

</tip>



More information about the thelist mailing list