>  기사  >  백엔드 개발  >  PHP判断搜索引擎蜘蛛并自动记忆到文件的代码_PHP教程

PHP判断搜索引擎蜘蛛并自动记忆到文件的代码_PHP教程

WBOY
WBOY원래의
2016-07-21 15:21:45875검색

复制代码 代码如下:

function write_naps_bot(){
$useragent=get_naps_bot();
// echoExit($useragent);
if ($useragent=="false") return FALSE ;
date_default_timezone_set("Asia/Shanghai");
$date=date("Y-m-d H:i:s");
$ip=$_SERVER[REMOTE_ADDR];
$url="http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
// echoExit($url);转载注明www.chhua.com
if (!file_exists("./log/bot.html")){
$botfile=fopen("./log/bot.html", "w");
$fileHeader="

访问查看

删除日志

";
// echoExit($botfile);转载注明www.chhua.com

fputs($botfile, $fileHeader);
fclose($botfile);
}else
{ $filesize=filesize("./log/bot.html");
if ($filesize>=100000){
$botfile=fopen("./log/bot.html", "w");
$fileHeader="

访问查看

删除日志

";
fputs($botfile, $fileHeader);
fclose($botfile);
}else {
$botfile=fopen("./log/bot.html", "a+");
}

//$size="当前文件大小为:".$filesize."
";转载注明www.chhua.com

$useragent="USER:".$useragent."
";
$date="TIME:".$date."
";
$ip="IP:".$ip."
";
$url="URL:".$url."

";
$fileStr=$useragent.$date.$ip.$url;
fputs($botfile, $fileStr);
fclose($botfile);
}
}

function get_naps_bot() {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($useragent, 'googlebot') !== false){
return 'Googlebot';
}
if(strpos($useragent, 'msnbot') !== false){
return 'MSNbot';
}
if(strpos($useragent, 'slurp') !== false){
return 'Yahoobot';
}
if(strpos($useragent, 'baiduspider') !== false){
return 'Baiduspider';
}
if(strpos($useragent, 'sohu-search') !== false){
return 'Sohubot';
}
if(strpos($useragent, 'lycos') !== false){
return 'Lycos';
}

if(strpos($useragent, 'robozilla') !== false){
return 'Robozilla';
}
return "false";
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324866.htmlTechArticle复制代码 代码如下: function write_naps_bot(){ $useragent=get_naps_bot(); // echoExit($useragent); if ($useragent=="false") return FALSE ; date_default_timezone_set("Asia/Sh...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.