每次下载页面时,根据$useragent判断客户端的类型,以此确定用户类型,如果是对用的蜘蛛,则把蜘蛛活动时间以及蜘蛛信息记录在文件中。


  1.  // $cachename:文件生成的地方和文件名,既你要放置的地方
  2.  
    function writefiles($cachename,$sData)
  3.  {
  4.          
  5.  
    $fp2 = @fopen($cachename,"w");
  6.  @
    flock($fp2,2);
  7.  @
    fwrite($fp2,$sData);
  8.  @
    fclose($fp2);        
  9.  
    $mystr="ok";
  10.  return        
    $mystr;
  11.  }
  12.  
  13.  
  14.  function
    get_naps_bot()
  15.  {
  16.  
    $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
  17.  
  18.  
  19.  if (
    strpos($useragent, "googlebot") !== false){
  20.  return
    'Googlebot';
  21.  }
  22.  
  23.  if (
    strpos($useragent, "Googlebot") !== false){
  24.  return
    'Googlebot';
  25.  }
  26.  
  27.  if (
    strpos($useragent, "msnbot") !== false){
  28.  return
    "MSNbot";
  29.  }
  30.  
  31.  if (
    strpos($useragent, "slurp") !== false){
  32.  return
    "Yahoobot";
  33.  }
  34.  
  35.  if (
    strpos($useragent, 'baiduspider') !== false){
  36.  return
    "Baiduspider";
  37.  }
  38.  
  39.  if (
    strpos($useragent, "sohu-search") !== false){
  40.  return
    "Sohubot";
  41.  }
  42.  
  43.  if (
    strpos($useragent, "lycos") !== false){
  44.  return
    "Lycos";
  45.  }
  46.  
  47.  if (
    strpos($useragent, "robozilla") !== false){
  48.  return
    "Robozilla";
  49.  }
  50.  
  51.  if (
    strpos($useragent, "SpiderMan") !== false){
  52.  return
    "SpiderMan";
  53.  }
  54.  
  55.  if (
    strpos($useragent, "Baiduspider") !== false){
  56.  return
    "Baiduspider";
  57.  }
  58.  
  59.  return
    false;
  60.  
  61.  
  62.  }
  63.  
  64.  
    $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
  65.  
    //添加蜘蛛的抓取记录
  66.  
    $searchbot = get_naps_bot();
  67.  
  68.  
  69.  
  70.  if (
    $searchbot) {
  71.  
  72.  
    $BotData="";
  73.  
    $BotData=$searchbot.",".$tlc_thispage.",".date("Y-m-d H:i:s");
  74.  
    writefiles("cache/".$searchbot.date("YmdHis").".txt",$BotData);
  75.  
    //echo"";
  76.  
    }
  77.  
  78.  
    ?>

Tags: , ,
搜索引擎优化SEO | 评论(1) | 引用(0) | 阅读(4096)
k8 Homepage
2006/10/29 09:42
love
分页: 1/1 第一页 [1] 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
昵称   密码  
网址   电邮   [注册]
               

验证码 请输入左侧的字母,不区分大小写