PHP判斷搜索引擎蜘蛛并自動記憶到文件的代碼
更新時間:2012年02月04日 14:51:18 作者:
為了記憶百度蜘蛛的行蹤,寫了以下的PHP函數(shù),分兩個函數(shù),一個是判斷蜘蛛名稱,一個是記憶蜘蛛到文件,可以自己看一下
復制代碼 代碼如下:
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="<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>訪問查看</title>
</head>
<a href=\"../?action=delbot\">刪除日志</a><hr>
";
// 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="<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>";轉載注明www.chhua.com
$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中3種方法統(tǒng)計字符串中每種字符的個數(shù)并排序
3種方法,統(tǒng)計字符串中每種字符的個數(shù)并排序,多種解法喲~ str_split()函數(shù)很重要2012-08-08
PHP調(diào)用QQ互聯(lián)接口實現(xiàn)QQ登錄網(wǎng)站功能示例
這篇文章主要介紹了PHP調(diào)用QQ互聯(lián)接口實現(xiàn)QQ登錄網(wǎng)站功能,結合實例形式分析php調(diào)用QQ互聯(lián)接口實現(xiàn)QQ登錄網(wǎng)站的相關操作技巧,需要的朋友可以參考下2019-10-10
php過濾htmlspecialchars() 函數(shù)實現(xiàn)把預定義的字符轉換為 HTML 實體用法分析
這篇文章主要介紹了php過濾htmlspecialchars() 函數(shù)實現(xiàn)把預定義的字符轉換為 HTML 實體用法,結合實例形式分析了htmlspecialchars()函數(shù)針對HTML進行字符轉義的相關操作技巧,需要的朋友可以參考下2019-06-06
php基于socket實現(xiàn)SMTP發(fā)送郵件的方法
這篇文章主要介紹了php基于socket實現(xiàn)SMTP發(fā)送郵件的方法,實例分析了php采用socket實現(xiàn)smtp發(fā)送郵件的原理與技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03

