PHP 进行蜘蛛访问日志统计
1 $useragent = addslashes(strtolower($_SERVER['HTTP_USER_AGENT'])); 2 3 if (strpos($useragent, 'googlebot')!== false){$bot = 'Google';} 4 elseif (strpos($useragent,'mediapartners-google') !== false){$bot = 'Google Adsense';} 5 elseif (strpos($useragent,'baiduspider') !== false){$bot = 'Baidu';} 6 elseif (strpos($useragent,'sogou spider') !== false){$bot = 'Sogou';} 7 elseif (strpos($useragent,'sogou web') !== false){$bot = 'Sogou web';} 8 elseif (strpos($useragent,'sosospider') !== false){$bot = 'SOSO';} 9 elseif (strpos($useragent,'360spider') !== false){$bot = '360Spider';} 10 elseif (strpos($useragent,'yahoo') !== false){$bot = 'Yahoo';} 11 elseif (strpos($useragent,'msn') !== false){$bot = 'MSN';} 12 elseif (strpos($useragent,'msnbot') !== false){$bot = 'msnbot';} 13 elseif (strpos($useragent,'sohu') !== false){$bot = 'Sohu';} 14 elseif (strpos($useragent,'yodaoBot') !== false){$bot = 'Yodao';} 15 elseif (strpos($useragent,'twiceler') !== false){$bot = 'Twiceler';} 16 elseif (strpos($useragent,'ia_archiver') !== false){$bot = 'Alexa_';} 17 elseif (strpos($useragent,'iaarchiver') !== false){$bot = 'Alexa';} 18 elseif (strpos($useragent,'slurp') !== false){$bot = '雅虎';} 19 elseif (strpos($useragent,'bot') !== false){$bot = '其它蜘蛛';} 20 if(isset($bot)){ 21 $fp = @fopen('bot.txt','a'); 22 fwrite($fp,date('Y-m-d H:i:s')."\t".$_SERVER["REMOTE_ADDR"]."\t".$bot."\t".'http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]."\r\n"); 23 fclose($fp); 24 }