wsknnh 发表于 2024-10-26 17:18:05

自用便于统计百度蜘蛛的php代码

<?php
//php直接输出蜘蛛日志
function get_naps_bot()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);

if (strpos($useragent, 'baiduspider') !== false){
    return 'Baidu';
}
return false;
}
function nowtime(){
    $date=gmdate("Y-n-j H:i:s",time()+8*3600);
    return $date;
}
$searchbot = get_naps_bot();
if ($searchbot) {
    $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
    $url=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $file="spiderlogs.txt";//输出到根目录任意命名方便访问即可
    $time=nowtime();
    $data=fopen($file,"a");
    fwrite($data,"Time:$time robot:$searchbot URL:$url\n");
    fclose($data);
}
?>在泛目录的index.php和404.php中插入:

include'spider.php';查看蜘蛛统计的话,访问:您的域名/spiderlogs.txt


以上代码转载出处:https://www.niuniubbs.com/thread-5072-1-1.html
页: [1]
查看完整版本: 自用便于统计百度蜘蛛的php代码