>>>>> "BC" == Brian Clark <[EMAIL PROTECTED]> writes:

 > Hello Dallas,

 > (DK == "Dallas Kropka") [EMAIL PROTECTED] writes:

 DK> Posted earlier but got no response.... so here it is again...

 > I gave you a quick explanation of one way to do it earlier, but I
 > know of no tutorials off the top of my head.

 > Here is a lengthy example if you _have_ to see code:

 (...)

 > But there has to be an easier solution out there that's already
 > been ridden to death. The above is going to get nasty rather
 > quickly I'd imagine, and every search engine, more than likely, is
 > going to have a completely different query string. There's no way
 > I'm going to look.  :)

Hiyah,

This is a slightly more flexible way of doing pretty much the same thing.
You can then log the output of search_term($HTTP_REFERER) for later analysis.

I've not split the search terms up into words (I'm thinking of how boolean 
searches like 'foo AND NOT bar' would skew the results and how search phrases
like 'foo AND "bar baz"' would be split up).

Unfortunately, the analysing the logs (properly) is going to be more of a job.

        -robin

<?php

function search_term( $referer ) 
{
  // search engines we know about and what they call their search terms.
  // Add your own, I can't be bothered to look at any more.
  $engine = array (
                   "www.altavista.com" => "q",
                   "www.google.com"    => "q",
                   "search.yahoo.com"  => "p",
                   "search.excite.com" => "search",
                   "www.lycos.com"     => "query",
                   "www.lycos.co.uk"   => "query"
                   );

  // if no referer's been passed, forget it.
  if(!isset($referer) || empty($referer) ) return false;

  // split the url into logical bits.
  $url = parse_url( $referer );

  // if we don't recognise the search engine forget it.
  if(! $terms = $engine[strtolower( $url['host'] )] ) return false;

  // parse the query part of the url and put it in $REFERER_GET_VARS.
  parse_str( $url['query'], $REFERER_GET_VARS );

  // find the appropriate value and return it together with the search engine as a 
hash.
  return array(
               "engine" => strtolower( $url['host'] ),
               "term"   => $REFERER_GET_VARS[$terms]
               );
}

print_r( search_term( $HTTP_REFERER ) );

?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to