首页 > 资讯列表 > 编程/数据库 >> PHP

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

PHP 2014-12-24 22:57:05 转载来源: 网络整理/侵权必删

本文是一个PHP判断搜索引擎蜘蛛并自动记忆到文件的代码示例,感兴趣的同学参考下. 为了记忆百度蜘蛛的行踪,写了以下的PHP函数,分两个函数,一个是判断蜘蛛名称,一个是记忆蜘蛛到文件,可以自己看一下 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://"

本文是一个PHP判断搜索引擎蜘蛛自动记忆文件代码示例,感兴趣的同学参考下.

为了记忆百度蜘蛛的行踪,写了以下的PHP函数,分两个函数,一个是判断蜘蛛名称,一个是记忆蜘蛛到文件,可以自己看一下


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);
if (!file_exists("./log/bot.html")){
$botfile=fopen("./log/bot.html", "w");
$fileHeader="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>访问查看</title>
</head>
<a href="../?action=delbot">删除日志</a><hr>
";
// echoExit($botfile);

fputs($botfile, $fileHeader);
fclose($botfile);
}else
{ $filesize=filesize("./log/bot.html");
if ($filesize>=100000){
$botfile=fopen("./log/bot.html", "w");
$fileHeader="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>访问查看</title>
</head>
<a href="../?action=delbot">删除日志</a><hr>
";
fputs($botfile, $fileHeader);
fclose($botfile);
}else {
$botfile=fopen("./log/bot.html", "a+");
}

//$size="<b>当前文件大小为:</b>".$filesize."<br>";

$useragent="<b>USER:</b>".$useragent."<Br>";
$date="<b>TIME:</b>".$date."<Br>";
$ip="<b>IP:</b>".$ip."<Br>";
$url="<b>URL:</b><a href='$url' target='_blank'>".$url."</a><Br><Br>";
$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 '<font color=blue>Googlebot</font>';
}
if(strpos($useragent, 'msnbot') !== false){
return 'MSNbot';
}
if(strpos($useragent, 'slurp') !== false){
return '<font color=green>Yahoobot</font>';
}
if(strpos($useragent, 'baiduspider') !== false){
return '<font color=red>Baiduspider</font>';
}
if(strpos($useragent, 'sohu-search') !== false){
return 'Sohubot';
}
if(strpos($useragent, 'lycos') !== false){
return 'Lycos';
}

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

标签: PHP 判断 搜索引擎 蜘蛛 自动 记忆 文件 代码 示例


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持