PHP judges the search engine spider and automatically remembers the file code

Source: Internet
Author: User

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 ";
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.