php记录搜索引擎爬行记录的实现代码

本文阅读 1 分钟
首页 › PHP笔记 › 正文
<?php

/**
 * 获取搜索引擎爬行记录
 */
function get_naps_bot()
{
    $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
    if (strpos($useragent, 'googlebot') !== false) {
        return 'Google';
    }
    if (strpos($useragent, 'baiduspider') !== false) {
        return 'Baidu';
    }
    if (strpos($useragent, 'msnbot') !== false) {
        return 'Bing';
    }
    if (strpos($useragent, 'slurp') !== false) {
        return 'Yahoo';
    }
    if (strpos($useragent, 'sosospider') !== false) {
        return 'Soso';
    }
    if (strpos($useragent, 'sogou spider') !== false) {
        return 'Sogou';
    }
    if (strpos($useragent, 'yodaobot') !== false) {
        return 'Yodao';
    }

    return false;
}

function nowtime()
{
    $date = date('Y-m-d.G:i:s');

    return $date;
}

$searchbot = get_naps_bot();

var_dump($searchbot); die;
if ($searchbot) {
    $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
    $url = $_SERVER['HTTP_REFERER'];
    $file = 'www.txt';
    $time = nowtime();
    $data = fopen($file, 'a');
    fwrite($data, "Time:$time robot:$searchbot URL:$tlc_thispage\n");
    fclose($data);
}

//记录搜索引擎爬行记录
// $searchbot = get_naps_bot();

// if ($searchbot) {
//     $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
//     $url = $_SERVER['HTTP_REFERER'];
//     $file = WEB_PATH.'api/robotslogs.txt';
//     $date = date('Y-m-d H:i:s');
//     $data = fopen($file, 'a');
//     fwrite($data, "Time:$date robot:$searchbot URL:$tlc_thispage/r/n");
//     fclose($data);
// }
tp5.1保存搜索条件
« 上一篇 12-03
PHP从JSON数据中获取字段值(支持多维度)
下一篇 » 12-08

发表评论

1 条回复
  1. 今日新闻游客

    文章不错非常喜欢

惪特博客
  • 文章总数:
    5298 篇
  • 评论总数:
    53894 条
  • 标签总数:
    6607 个
  • 总浏览量:
    37577663 次
  • 最后更新:
    昨天 09:44

最多点赞

随便看看

标签TAG