You are here

function search404_search_engine_query in Search 404 5

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

Detect search from search engine (BETA) WARNING: This function can potentially return dangerous potential SQL inject/XSS data. Return must be sanatized before use.

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 Beware of messy code

File

./search404.module, line 76

Code

function search404_search_engine_query() {
  $engines = array(
    'altavista' => 'q',
    'aol' => 'query',
    'google' => 'q',
    'live' => 'q',
    'lycos' => 'query',
    'msn' => 'q',
    'yahoo' => 'p',
  );
  $parsed_url = parse_url($_SERVER['HTTP_REFERER']);
  drupal_set_message('Parsed url :' . $parsed_url);
  $remote_host = $parsed_url['host'];
  drupal_set_message('Remote host :' . $remote_host);
  $query_string = $parsed_url['query'];
  drupal_set_message('Query string :' . $query_string);
  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;
}