/** * count visitor info * @return boolean */ public function Count() { //$this->FileLog("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI] \n", 'fff.txt'); // if is visited count $rs = $this->db->Select('SELECT statistic_id FROM %table% WHERE statistic_ip = ' . _ipi() . ' AND statistic_last_visit > ' . (time() - VISIT_LONG), array('statistic')); if (is_array($rs) && count($rs) > 0) { $this->db->Select('UPDATE %table% SET statistic_visit = statistic_visit + 1' . ', statistic_last_visit = ' . time() . ' WHERE statistic_id = ' . $rs[0]['statistic_id'], array('statistic')); } else { // $data = array('statistic_time' => time(), 'statistic_last_visit' => time(), 'statistic_os' => TVisitor::DetectOSI(), 'statistic_browser' => TVisitor::DetectBrowserI(), 'statistic_verstion' => (int) TVisitor::BrowserVersion(), 'statistic_ip' => _ipi(), 'statistic_referer' => Referer(), 'statistic_keyword' => TVisitor::GetKeyword()); $this->Create($data); } return TRUE; }
/** * get searched keywords * @param string $referer * @return string * @author http://www.codediesel.com/php/grabbing-the-referrer-search-engine-keywords-for-a-site/ */ public static function GetKeyword($referer = 'Referer()') { if ($referer == 'Referer()') { $referer = Referer(); } // pre _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $referer); $search_phrase = ''; $engines = array('dmoz' => 'q=', 'aol' => 'q=', 'ask' => 'q=', 'google' => 'q=', 'bing' => 'q=', 'hotbot' => 'q=', 'teoma' => 'q=', 'yahoo' => 'p=', 'altavista' => 'p=', 'lycos' => 'query=', 'kanoodle' => 'query='); foreach ($engines as $engine => $query_param) { // Check if the referer is a search engine from our list. // Also check if the query parameter is valid. if (strpos($referer, $engine . ".") !== false && strpos($referer, $query_param) !== false) { // Grab the keyword from the referer url $referer .= "&"; $pattern = "/[?&]{$query_param}(.*?)&/si"; preg_match($pattern, $referer, $matches); $search_phrase = urldecode($matches[1]); // return array($engine, $search_phrase); } else { $search_phrase = null; } } // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $result); return $result; }