You are here

function search404_search_engine_query in Search 404 6

Same name and namespace in other branches
  1. 5 search404.module \search404_search_engine_query()
  2. 7 search404.page.inc \search404_search_engine_query()

Detect search from search engine.

1 call to search404_search_engine_query()
search404_page in ./search404.module
Main search function. Started with: http://drupal.org/node/12668 Updated to be more similar to search_view

File

./search404.module, line 83

Code

function search404_search_engine_query() {
  $engines = array(
    'altavista' => 'q',
    'aol' => 'query',
    'google' => 'q',
    'bing' => 'q',
    'lycos' => 'query',
    'yahoo' => 'p',
  );

  // Try to extract searchengine querystring only if HTTP_REFERER was set (#1111918)
  if (isset($_SERVER['HTTP_REFERER'])) {
    $parsed_url = parse_url($_SERVER['HTTP_REFERER']);
    $remote_host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
    $query_string = isset($parsed_url['query']) ? $parsed_url['query'] : '';
    parse_str($query_string, $query);
    if (!$parsed_url === FALSE && !empty($remote_host) && !empty($query_string) && count($query)) {
      foreach ($engines as $host => $key) {
        if (strpos($remote_host, $host) !== FALSE && array_key_exists($key, $query)) {
          return trim($query[$key]);
        }
      }
    }
  }
  return FALSE;
}