zoukankan      html  css  js  c++  java
  • php判断爬虫

    function checkrobot($useragent = ''){

    static $kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';

    static $kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';

    $useragent = empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent;

    if(!strexists($useragent, 'http://') && preg_match("/($kw_browsers)/i", $useragent)) {

    return false;

    } elseif(preg_match("/($kw_spiders)/i", $useragent)) {

    return true;

    } else {

    return false;

    }

    }

    function strexists($haystack, $needle) {
    return !(strpos($haystack, $needle) === FALSE);
    }
    if(checkrobot()){
    echo '机器人爬虫';
    }else{
    echo '人';
    }
    ?>

    <?php
    function checkrobot($useragent=''){
    static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla');
    static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');

    $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
    if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false;
    if(dstrpos($useragent, $kw_spiders)) return true;
    return false;
    }

    function dstrpos($string, $arr, $returnvalue = false) {
    if(empty($string)) return false;
    foreach((array)$arr as $v) {
    if(strpos($string, $v) !== false) {
    $return = $returnvalue ? $v : true;
    return $return;
    }
    }
    return false;
    }

    if(checkrobot()){
    echo '机器人爬虫';
    }else{
    echo '人';
    }
    ?>

  • 相关阅读:
    围棋GO
    Android 四大组件------Activity
    android studio----设备兼容
    android UI开发--------Action Bar
    开发调试工具----DDMS
    RxJava的使用
    Atlas框架
    Android studio上git的使用
    AS上git的使用与遇到的问题
    picasso-安卓的图片下载缓存库
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/5056975.html
Copyright © 2011-2022 走看看