使用PHP实现蜘蛛访问日志统计
程序员文章站
2023-11-10 15:08:52
复制代码 代码如下:$useragent = addslashes(strtolower($_server['http_user_agent'])); if (s...
复制代码 代码如下:
$useragent = addslashes(strtolower($_server['http_user_agent']));
if (strpos($useragent, 'googlebot')!== false){$bot = 'google';}
elseif (strpos($useragent,'mediapartners-google') !== false){$bot = 'google adsense';}
elseif (strpos($useragent,'baiduspider') !== false){$bot = 'baidu';}
elseif (strpos($useragent,'sogou spider') !== false){$bot = 'sogou';}
elseif (strpos($useragent,'sogou web') !== false){$bot = 'sogou web';}
elseif (strpos($useragent,'sosospider') !== false){$bot = 'soso';}
elseif (strpos($useragent,'360spider') !== false){$bot = '360spider';}
elseif (strpos($useragent,'yahoo') !== false){$bot = 'yahoo';}
elseif (strpos($useragent,'msn') !== false){$bot = 'msn';}
elseif (strpos($useragent,'msnbot') !== false){$bot = 'msnbot';}
elseif (strpos($useragent,'sohu') !== false){$bot = 'sohu';}
elseif (strpos($useragent,'yodaobot') !== false){$bot = 'yodao';}
elseif (strpos($useragent,'twiceler') !== false){$bot = 'twiceler';}
elseif (strpos($useragent,'ia_archiver') !== false){$bot = 'alexa_';}
elseif (strpos($useragent,'iaarchiver') !== false){$bot = 'alexa';}
elseif (strpos($useragent,'slurp') !== false){$bot = '雅虎';}
elseif (strpos($useragent,'bot') !== false){$bot = '其它蜘蛛';}
if(isset($bot)){
$fp = @fopen('bot.txt','a');
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");
fclose($fp);
}