You are here

function search404_search_engine_query in Search 404 7

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

Detect search from search engine.

1 call to search404_search_engine_query()
search404_get_keys in ./search404.page.inc
Get the keys that are to be used for the search.

File

./search404.page.inc, line 69
The search404 module search page related functions.

Code

function search404_search_engine_query() {
  $engines = array(
    'altavista' => 'q',
    'aol' => 'query',
    'google' => 'q',
    'bing' => 'q',
    'lycos' => 'query',
    'yahoo' => 'p',
  );
  $parsed_url = !empty($_SERVER['HTTP_REFERER']) ? parse_url($_SERVER['HTTP_REFERER']) : FALSE;
  $remote_host = !empty($parsed_url['host']) ? $parsed_url['host'] : '';
  $query_string = !empty($parsed_url['query']) ? $parsed_url['query'] : '';
  $query = array();
  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 '';
}