Extract the search term from google referer
$referer = strtolower($_SERVER['HTTP_REFERER']); // Test if user comes from google if (strpos($referer, 'google')) { // Delete all before &q= $tmp = substr($referer, strpos($referer, 'q=')); // Remove q= $tmp = substr($tmp, 2); // Remove everything after the next & if (strpos($tmp, '&')) { $tmp = substr($tmp, 0,strpos($tmp, '&')); } // we have the results. $searchTerm = urldecode($tmp); }
Takes the referer and extracts the search term, if user comes from google.
Most popular snippets