visited(); //调用统计函数(最好放在公共页面)
//访问量 function visited(){ $now_time = time(); $referer_url = $_SERVER['HTTP_REFERER']; //来自的页面地址 $from_spider = $keywords = ''; if(!empty($referer_url)){ if(strstr($referer_url,'www.baidu.com')){ $referer_url = explode("&",$referer_url); foreach($referer_url as $val){ if(strstr($val,'wd=')){ $keywords = explode("wd=",$val); $keywords = $keywords[1]; } } $from_spider = '百度'; $keywords = urldecode($keywords); }elseif(strstr($referer_url,'www.google')){ $referer_url = explode("&",$referer_url); foreach($referer_url as $val){ if(strstr($val,'q=')){ $keywords = explode("q=",$val); $keywords = $keywords[1]; } } $from_spider = '谷歌'; $keywords = urldecode($keywords); } } //只判断了百度和谷歌的,其他的原理一样 $theData = array( 'access_time' => $now_time, 'access_date' => date("Y-m-d",$now_time), 'access_url' => $_SERVER['REQUEST_URI'], 'referer_url' => $_SERVER['HTTP_REFERER'], 'keywords' => $keywords, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'from_spider' => $from_spider, ); $sql = "insert into stats (access_time,access_date,access_url,referer_url,keywords,ip_address,from_spider) values ('".$theData['access_time']."','".$theData['access_date']."','".$theData['access_url']."','".$theData['referer_url']."','".$theData['keywords']."','".$theData['ip_address']."','".$theData['from_spider']."')"; echo $sql; exit;mysql_query($sql); } |