CoderZone.org

Category: >> PHP Code >> Extract Search Query from Referer Bookmark and Share

<< lastnext >>

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)

Author: CoderZone
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'";
 
?>
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 7