Copy CodeThe code is as follows:
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); reprint Annotated www.chhua.com
if (!file_exists ("./log/bot.html")) {
$botfile =fopen ("./log/bot.html", "w");
$fileHeader = "
<title>Access to view</title>
Delete Log
";
Echoexit ($botfile); reprint Annotated www.chhua.com
Fputs ($botfile, $fileHeader);
Fclose ($botfile);
}else
{$filesize =filesize ("./log/bot.html");
if ($filesize >=100000) {
$botfile =fopen ("./log/bot.html", "w");
$fileHeader = "
<title>Access to view</title>
Delete Log
";
Fputs ($botfile, $fileHeader);
Fclose ($botfile);
}else {
$botfile =fopen ("./log/bot.html", "A +");
}
$size = "The current file size is:". $filesize."
"; Reproduced annotated 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";
}
The above introduces the new science and technology of beauty search engine PHP judge search engine spiders and automatically remember the code, including the new technology of beauty search engine aspects of the content, I hope that the PHP tutorial interested in a friend helpful.