<?
/*
 
 本软件版权归作者所有,在投入使用之前注意获取许可
 作者：程威（wiwiboy）
 项目：PHPStat流量统计 1.0
 电话：13553166317
 邮箱：wiwiboy@126.com
 QQ号：158839753
 网址：http://www.phpstat.net
 phpstat.net保留全部权力，受相关法律和国际		  		
		公约保护，请勿非法修改、转载、散播，或用于其他赢利行为，		
		并请勿删除版权声明。
*/
/*	
	verson:v1.0 20060618
	author:wiwiboy
	last update:2006/06/10
*/

	
	$prefix  = "[PREFIX]";
	$website = "[SITENAME]";
	
	$lang   = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
	$bot    = $_SERVER['HTTP_USER_AGENT'];	
	$cookie = $_SERVER['HTTP_COOKIE'];	
	
	$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
	If ($ip == "") $ip = $_SERVER["REMOTE_ADDR"];
	$ipArray = explode(".",$ip);
	if( count($ipArray) == '4')
	$ip = $ipArray[0].".".$ipArray[1].".".$ipArray[2].".*";
		//网络蜘蛛
		function GetNapsBot($bot1)
		{
			$useragent = strtolower($bot1);
							
			if (strstr($useragent, 'googlebot')){
					$bot = 'Googlebot';
			}
			
			else if (strstr($useragent, 'msnbot')){
					$bot = 'MSNbot';
			}
			
			else if (strstr($useragent, 'slurp')){
					$bot = 'Yahoobot';
			}
			
			else if (strstr($useragent, 'baiduspider')){
					$bot = 'Baiduspider';
			}
			
			else if (strstr($useragent, 'sohu-search')){
					$bot = 'Sohubot';
			}
			
			else if (strstr($useragent, 'lycos')){
					$bot = 'Lycos';
			}
			
			else if (strstr($useragent, 'robozilla')){
					$bot = 'Robozilla';
			}
			else if (strstr($useragent, 'sphider')){
					$bot = 'Sphider';
			}
			else if (strstr($useragent, 'hl_ftien_spider')){
					$bot = 'hl_ftien_spider';
			}
			else if (strstr($useragent, 'qihoobot')){
					$bot = 'QihooBot';
			}
			else if (strstr($useragent, 'sogou spider')){
					$bot = 'Sogou spider';
			}
			else if (strstr($useragent, 'iaskspider')){
					$bot = 'IaskSpider';
			}			
			else
				$bot = '0';
			return $bot;
		}

	$bot = GetNapsBot($bot);
	$time = mktime(0,0,0,date('m'),date('d'),date('Y'));
	if (empty($cookie) and $bot != '0') 
	{
		if (empty($lang))
		{	
			$link    = mysql_connect("[HOST]","[USER]","[PASSWORD]");
					   mysql_select_db("[DBNAME]",$link);
			$vrs     = mysql_query("select version() as version");
			$vrsrow  = mysql_fetch_array($vrs);
			$Version = $vrsrow[version];
			$Version = substr($Version,0,1);
			if( $Version > 4 )
			mysql_query("SET names '[CHARSET]'");
			
			$Res = mysql_query( " select count(botid) as count from ".$prefix."bot where website = '$website' and times = '$time' and bot = '$bot' and lastpage = '$ip'" );
			$Tmp = mysql_fetch_array($Res);
			if( $Tmp['count'] > 0 )
			{
				mysql_query( " update ".$prefix."bot set counts = counts +1 where website = '$website' and times = '$time' and bot = '$bot' and lastpage = '$ip'" );
			}
			else
			{
				mysql_query( " insert into ".$prefix."bot(website,bot,times,lastpage,counts,types) values ('$website','$bot','$time','$ip','1','1')" );
			}
			
		}
	}

?>