Snippet Name: Extract Search Query from Referer
Description: This will extract the search query from a search engine's search. You can use this information to perform the search on your own site or just keep it for your own records.
Comment: (none)
Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009
|
<?PHP
$referer = $_SERVER[HTTP_REFERER];
IF($referer)
{
PREG_MATCH("/[\&\?]q=([^&]*)/", $referer, $matches);
IF($matches[1])
{
$search_query = RAWURLDECODE($matches[1]);
$search_query = STR_REPLACE("+", " ", $search_query);
}
}
PRINT "You searched for '$search_query'";
?> |