• Posted: 2011-01-07
  • Author: Ugosta
  • Tags:

Display search terms from Google users

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
<?php
$refer = $_SERVER["HTTP_REFERER"];
if (strpos($refer, "google")) {
	$refer_string = parse_url($refer, PHP_URL_QUERY);
	parse_str($refer_string, $vars);
	$search_terms = $vars['q'];
	echo 'Welcome Google visitor! You searched for the following terms to get here: ';
	echo $search_terms;
};
?>

Instructions:

If a visitor reached your site through Google’s search, this script will display the terms they searched for in order to find your site. Put this code where you want to display the message.


Share this snippet

If you like this snippet, share it with friends!