近期,百度很疯,老李说了,5年之后,互联网无垃圾,不知道他所谓的垃圾是什么?采集的,还是什么的?咱不去管他,最近,我总是很倒霉,百度就好像专门针对我一样,排名好的站总是得K我,排名不好的站,一点也不会出事,为了记忆百度蜘蛛的行踪,写了以下的PHP函数,分两个函数,一个是判断蜘蛛名称,一个是记忆蜘蛛到文件,可以自己看一下,不懂的留言。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<span style="color: #000000;font-weight: bold">function</span> write_naps_bot<span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #009900">{</span>
    	 <span style="color: #000088">$useragent</span><span style="color: #339933">=</span>get_naps_bot<span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	<span style="color: #666666;font-style: italic">// echoExit($useragent);</span>
    	 <span style="color: #b1b100">if</span> <span style="color: #009900">(</span><span style="color: #000088">$useragent</span><span style="color: #339933">==</span><span style="color: #0000ff">"false"</span><span style="color: #009900">)</span> <span style="color: #b1b100">return</span> <span style="color: #009900;font-weight: bold">FALSE</span> <span style="color: #339933">;</span>
    	 <a rel="noopener noreferrer nofollow" href="http://www.php.net/date_default_timezone_set" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">date_default_timezone_set</span></a><span style="color: #009900">(</span><span style="color: #0000ff">"Asia/Shanghai"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 <span style="color: #000088">$date</span><span style="color: #339933">=</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/date" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">date</span></a><span style="color: #009900">(</span><span style="color: #0000ff">"Y-m-d H:i:s"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 <span style="color: #000088">$ip</span><span style="color: #339933">=</span><span style="color: #000088">$_SERVER</span><span style="color: #009900">[</span>REMOTE_ADDR<span style="color: #009900">]</span><span style="color: #339933">;</span>
    	 <span style="color: #000088">$url</span><span style="color: #339933">=</span><span style="color: #0000ff">"http://"</span><span style="color: #339933">.</span><span style="color: #000088">$_SERVER</span><span style="color: #009900">[</span>HTTP_HOST<span style="color: #009900">]</span><span style="color: #339933">.</span><span style="color: #000088">$_SERVER</span><span style="color: #009900">[</span>REQUEST_URI<span style="color: #009900">]</span><span style="color: #339933">;</span>
    	<span style="color: #666666;font-style: italic">// echoExit($url);转载注明www.chhua.com</span>
    	 <span style="color: #b1b100">if</span> <span style="color: #009900">(</span><span style="color: #339933">!</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/file_exists" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">file_exists</span></a><span style="color: #009900">(</span><span style="color: #0000ff">"./log/bot.html"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #009900">{</span>
    	 	<span style="color: #000088">$botfile</span><span style="color: #339933">=</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/fopen" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fopen</span></a><span style="color: #009900">(</span><span style="color: #0000ff">"./log/bot.html"</span><span style="color: #339933">,</span> <span style="color: #0000ff">"w"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 	 <span style="color: #000088">$fileHeader</span><span style="color: #339933">=</span><span style="color: #0000ff">"<head>
<meta http-equiv=<span style="color: #000099;font-weight: bold">\"</span>Content-Type<span style="color: #000099;font-weight: bold">\"</span> content=<span style="color: #000099;font-weight: bold">\"</span>text/html; charset=utf-8<span style="color: #000099;font-weight: bold">\"</span> />
<title>访问查看</title>
</head>
<a href=<span style="color: #000099;font-weight: bold">\"</span>../?action=delbot<span style="color: #000099;font-weight: bold">\"</span>>删除日志</a><hr>
"</span><span style="color: #339933">;</span>
    	 	<span style="color: #666666;font-style: italic">// echoExit($botfile);转载注明www.chhua.com</span>
 
    	 	 <a rel="noopener noreferrer nofollow" href="http://www.php.net/fputs" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fputs</span></a><span style="color: #009900">(</span><span style="color: #000088">$botfile</span><span style="color: #339933">,</span> <span style="color: #000088">$fileHeader</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 	 <a rel="noopener noreferrer nofollow" href="http://www.php.net/fclose" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fclose</span></a><span style="color: #009900">(</span><span style="color: #000088">$botfile</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 <span style="color: #009900">}</span><span style="color: #b1b100">else</span>
    	 <span style="color: #009900">{</span>	<span style="color: #000088">$filesize</span><span style="color: #339933">=</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/filesize" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">filesize</span></a><span style="color: #009900">(</span><span style="color: #0000ff">"./log/bot.html"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 	<span style="color: #b1b100">if</span> <span style="color: #009900">(</span><span style="color: #000088">$filesize</span><span style="color: #339933">>=</span><span style="color: #cc66cc">100000</span><span style="color: #009900">)</span><span style="color: #009900">{</span>
    	 		<span style="color: #000088">$botfile</span><span style="color: #339933">=</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/fopen" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fopen</span></a><span style="color: #009900">(</span><span style="color: #0000ff">"./log/bot.html"</span><span style="color: #339933">,</span> <span style="color: #0000ff">"w"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 		<span style="color: #000088">$fileHeader</span><span style="color: #339933">=</span><span style="color: #0000ff">"<head>
<meta http-equiv=<span style="color: #000099;font-weight: bold">\"</span>Content-Type<span style="color: #000099;font-weight: bold">\"</span> content=<span style="color: #000099;font-weight: bold">\"</span>text/html; charset=utf-8<span style="color: #000099;font-weight: bold">\"</span> />
<title>访问查看</title>
</head>
<a href=<span style="color: #000099;font-weight: bold">\"</span>../?action=delbot<span style="color: #000099;font-weight: bold">\"</span>>删除日志</a><hr>
"</span><span style="color: #339933">;</span>
    	 	 <a rel="noopener noreferrer nofollow" href="http://www.php.net/fputs" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fputs</span></a><span style="color: #009900">(</span><span style="color: #000088">$botfile</span><span style="color: #339933">,</span> <span style="color: #000088">$fileHeader</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 	 <a rel="noopener noreferrer nofollow" href="http://www.php.net/fclose" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fclose</span></a><span style="color: #009900">(</span><span style="color: #000088">$botfile</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 	<span style="color: #009900">}</span><span style="color: #b1b100">else</span> <span style="color: #009900">{</span>
    	 		<span style="color: #000088">$botfile</span><span style="color: #339933">=</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/fopen" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fopen</span></a><span style="color: #009900">(</span><span style="color: #0000ff">"./log/bot.html"</span><span style="color: #339933">,</span> <span style="color: #0000ff">"a+"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 	<span style="color: #009900">}</span>
 
    	 	<span style="color: #666666;font-style: italic">//$size="<b>当前文件大小为:</b>".$filesize."<br>";转载注明www.chhua.com</span>
 
    	 	<span style="color: #000088">$useragent</span><span style="color: #339933">=</span><span style="color: #0000ff">"<b>USER:</b>"</span><span style="color: #339933">.</span><span style="color: #000088">$useragent</span><span style="color: #339933">.</span><span style="color: #0000ff">"<Br>"</span><span style="color: #339933">;</span>
	    	 <span style="color: #000088">$date</span><span style="color: #339933">=</span><span style="color: #0000ff">"<b>TIME:</b>"</span><span style="color: #339933">.</span><span style="color: #000088">$date</span><span style="color: #339933">.</span><span style="color: #0000ff">"<Br>"</span><span style="color: #339933">;</span>
	    	 <span style="color: #000088">$ip</span><span style="color: #339933">=</span><span style="color: #0000ff">"<b>IP:</b>"</span><span style="color: #339933">.</span><span style="color: #000088">$ip</span><span style="color: #339933">.</span><span style="color: #0000ff">"<Br>"</span><span style="color: #339933">;</span>
	    	 <span style="color: #000088">$url</span><span style="color: #339933">=</span><span style="color: #0000ff">"<b>URL:</b><a href='<span style="color: #006699;font-weight: bold">$url</span>' target='_blank'>"</span><span style="color: #339933">.</span><span style="color: #000088">$url</span><span style="color: #339933">.</span><span style="color: #0000ff">"</a><Br><Br>"</span><span style="color: #339933">;</span>
	    	 <span style="color: #000088">$fileStr</span><span style="color: #339933">=</span><span style="color: #000088">$useragent</span><span style="color: #339933">.</span><span style="color: #000088">$date</span><span style="color: #339933">.</span><span style="color: #000088">$ip</span><span style="color: #339933">.</span><span style="color: #000088">$url</span><span style="color: #339933">;</span>  	
	    	 <a rel="noopener noreferrer nofollow" href="http://www.php.net/fputs" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fputs</span></a><span style="color: #009900">(</span><span style="color: #000088">$botfile</span><span style="color: #339933">,</span> <span style="color: #000088">$fileStr</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
	    	 <a rel="noopener noreferrer nofollow" href="http://www.php.net/fclose" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">fclose</span></a><span style="color: #009900">(</span><span style="color: #000088">$botfile</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
    	 <span style="color: #009900">}</span>
    <span style="color: #009900">}</span>
 
<span style="color: #000000;font-weight: bold">function</span> get_naps_bot<span style="color: #009900">(</span><span style="color: #009900">)</span>   <span style="color: #009900">{</span>          
    <span style="color: #000088">$useragent</span> <span style="color: #339933">=</span> <a rel="noopener noreferrer nofollow" href="http://www.php.net/strtolower" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">strtolower</span></a><span style="color: #009900">(</span><span style="color: #000088">$_SERVER</span><span style="color: #009900">[</span><span style="color: #0000ff">'HTTP_USER_AGENT'</span><span style="color: #009900">]</span><span style="color: #009900">)</span><span style="color: #339933">;</span>                                   
    <span style="color: #b1b100">if</span><span style="color: #009900">(</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/strpos" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">strpos</span></a><span style="color: #009900">(</span><span style="color: #000088">$useragent</span><span style="color: #339933">,</span> <span style="color: #0000ff">'googlebot'</span><span style="color: #009900">)</span> <span style="color: #339933">!==</span> <span style="color: #009900;font-weight: bold">false</span><span style="color: #009900">)</span><span style="color: #009900">{</span>                   
        <span style="color: #b1b100">return</span> <span style="color: #0000ff">'<font color=blue>Googlebot</font>'</span><span style="color: #339933">;</span>           
    <span style="color: #009900">}</span>                    
    <span style="color: #b1b100">if</span><span style="color: #009900">(</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/strpos" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">strpos</span></a><span style="color: #009900">(</span><span style="color: #000088">$useragent</span><span style="color: #339933">,</span> <span style="color: #0000ff">'msnbot'</span><span style="color: #009900">)</span> <span style="color: #339933">!==</span> <span style="color: #009900;font-weight: bold">false</span><span style="color: #009900">)</span><span style="color: #009900">{</span>                   
        <span style="color: #b1b100">return</span> <span style="color: #0000ff">'MSNbot'</span><span style="color: #339933">;</span>          
    <span style="color: #009900">}</span>                   
    <span style="color: #b1b100">if</span><span style="color: #009900">(</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/strpos" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">strpos</span></a><span style="color: #009900">(</span><span style="color: #000088">$useragent</span><span style="color: #339933">,</span> <span style="color: #0000ff">'slurp'</span><span style="color: #009900">)</span> <span style="color: #339933">!==</span> <span style="color: #009900;font-weight: bold">false</span><span style="color: #009900">)</span><span style="color: #009900">{</span>                  
       <span style="color: #b1b100">return</span> <span style="color: #0000ff">'<font color=green>Yahoobot</font>'</span><span style="color: #339933">;</span>          
    <span style="color: #009900">}</span>                     
    <span style="color: #b1b100">if</span><span style="color: #009900">(</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/strpos" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">strpos</span></a><span style="color: #009900">(</span><span style="color: #000088">$useragent</span><span style="color: #339933">,</span> <span style="color: #0000ff">'baiduspider'</span><span style="color: #009900">)</span> <span style="color: #339933">!==</span> <span style="color: #009900;font-weight: bold">false</span><span style="color: #009900">)</span><span style="color: #009900">{</span>                  
        <span style="color: #b1b100">return</span> <span style="color: #0000ff">'<font color=red>Baiduspider</font>'</span><span style="color: #339933">;</span>          
    <span style="color: #009900">}</span>                   
    <span style="color: #b1b100">if</span><span style="color: #009900">(</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/strpos" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">strpos</span></a><span style="color: #009900">(</span><span style="color: #000088">$useragent</span><span style="color: #339933">,</span> <span style="color: #0000ff">'sohu-search'</span><span style="color: #009900">)</span> <span style="color: #339933">!==</span> <span style="color: #009900;font-weight: bold">false</span><span style="color: #009900">)</span><span style="color: #009900">{</span>                  
       <span style="color: #b1b100">return</span> <span style="color: #0000ff">'Sohubot'</span><span style="color: #339933">;</span>          
    <span style="color: #009900">}</span>                   
    <span style="color: #b1b100">if</span><span style="color: #009900">(</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/strpos" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">strpos</span></a><span style="color: #009900">(</span><span style="color: #000088">$useragent</span><span style="color: #339933">,</span> <span style="color: #0000ff">'lycos'</span><span style="color: #009900">)</span> <span style="color: #339933">!==</span> <span style="color: #009900;font-weight: bold">false</span><span style="color: #009900">)</span><span style="color: #009900">{</span>                  
        <span style="color: #b1b100">return</span> <span style="color: #0000ff">'Lycos'</span><span style="color: #339933">;</span>          
    <span style="color: #009900">}</span> 
 
    <span style="color: #b1b100">if</span><span style="color: #009900">(</span><a rel="noopener noreferrer nofollow" href="http://www.php.net/strpos" rel="noopener noreferrer nofollow" target="_blank"><span style="color: #990000">strpos</span></a><span style="color: #009900">(</span><span style="color: #000088">$useragent</span><span style="color: #339933">,</span> <span style="color: #0000ff">'robozilla'</span><span style="color: #009900">)</span> <span style="color: #339933">!==</span> <span style="color: #009900;font-weight: bold">false</span><span style="color: #009900">)</span><span style="color: #009900">{</span>                  
        <span style="color: #b1b100">return</span> <span style="color: #0000ff">'Robozilla'</span><span style="color: #339933">;</span>         
    <span style="color: #009900">}</span>               
    <span style="color: #b1b100">return</span> <span style="color: #0000ff">"false"</span><span style="color: #339933">;</span>  
<span style="color: #009900">}</span>