- 帖子
- 212
- 主题
- 189
- 精华
- 0
- 积分
- 1452
- 贡献
- 1134
- 激情
- 1349
- 阅读权限
- 100
- 最后登录
- 2018-6-13
|
PHP版的捕捉搜索引擎蜘蛛爬行的代码
# p9 x8 B8 i4 b( V+ u% O/ A( k- T/ H- G- o: @9 M2 d
) z7 j& P8 q6 k* e8 {
- <?php
- /*
- 使用方法:
- 把以下代码粘贴到你想监控的页面php代码的之间的开头或结尾即可(也可以放在模板文件内)
- */
- 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;
- }
- function nowtime(){
- $date=date("Y-m-d.G:i:s");
- return $date;
- }
- $searchbot = get_naps_bot();
- if ($searchbot) {
- $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
- $url=$_SERVER['HTTP_REFERER'];
- $file="robotlog.txt";
- $time=nowtime();
- $data=fopen($file,"a");
- fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n");
- fclose($data);
- }
- ?>
复制代码 0 u- f5 |( k! d+ b
. s$ g% v8 g. Q0 r! F1 A& a参考: 网络 |
|