referer = urldecode(($_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : $_ENV['HTTP_REFERER'])); $this->sep = (eregi('(\?q=|\?qt=|\?p=)', $this->referer)) ? '\?' : '\&'; } } /** * Gets the search engine and keywords. * * @param void * @return array */ function get_keys() { if (!empty($this->referer)) { if (eregi('www\.google', $this->referer)) { // Google preg_match('#' . $this->sep . 'q=(.*?)\&#si', $this->referer, $this->keys); $this->search_engine = 'Google'; } else if (eregi('(yahoo\.com|search\.yahoo)', $this->referer)) { // Yahoo preg_match('#' . $this->sep . 'p=(.*?)\&#si', $this->referer, $this->keys); $this->search_engine = 'Yahoo'; } else if (eregi('search\.msn', $this->referer)) { // MSN preg_match('#' . $this->sep . 'q=(.*?)\&#si', $this->referer, $this->keys); $this->search_engine = 'MSN'; } else if (eregi('www\.alltheweb', $this->referer)) { // AllTheWeb preg_match('#' . $this->sep . 'q=(.*?)\&#si', $this->referer, $this->keys); $this->search_engine = 'AllTheWeb'; } else if (eregi('(looksmart\.com|search\.looksmart)', $this->referer)) { // Looksmart preg_match('#' . $this->sep . 'qt=(.*?)\&#si', $this->referer, $this->keys); $this->search_engine = 'Looksmart'; } else if (eregi('(askjeeves\.com|ask\.com)', $this->referer)) { // AskJeeves preg_match('#' . $this->sep . 'q=(.*?)\&#si', $this->referer, $this->keys); $this->search_engine = 'AskJeeves'; } else { $this->keys = 'Not available'; $this->search_engine = 'Unknown'; } return array( $this->referer, (!is_array($this->keys) ? $this->keys : $this->keys[1]), $this->search_engine ); } else { return array(); } } } ?> Example get_keys(); if (count($keys)) { echo "Referring URL: $keys[0]
Keywords: $keys[1]
Search Engine: $keys[2]"; } ?>