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); reprinted with www.chhua.com
If (! File_exists ("./log/bot.html ")){
$ Botfile = fopen ("./log/bot.html", "w ");
$ FileHeader = "<Meta http-equiv = \ "Content-Type \" content = \ "text/html; charset = UTF-8 \"/>
<Title> access view </title>
</Head>
<A href = \"../? Action = delbot \ "> delete logs </a> ";
// EchoExit ($ botfile); reprinted with www.chhua.com
Fputs ($ botfile, $ fileHeader );
Fclose ($ botfile );
} Else
{$ Filesize = filesize ("./log/bot.html ");
If ($ filesize> = 100000 ){
$ Botfile = fopen ("./log/bot.html", "w ");
$ FileHeader = "<Meta http-equiv = \ "Content-Type \" content = \ "text/html; charset = UTF-8 \"/>
<Title> access view </title>
</Head>
<A href = \"../? Action = delbot \ "> delete logs </a> ";
Fputs ($ botfile, $ fileHeader );
Fclose ($ botfile );
} Else {
$ Botfile = fopen ("./log/bot.html", "a + ");
}
// $ Size = "<B> current file size: </B>". $ filesize. "<br>"; reprinted with 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> ";
$ 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, 'baidider ider ')! = 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 ";
}