1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php 判断爬虫程序 php判断搜索引擎蜘蛛爬虫还是人为访问代码

php 判断爬虫程序 php判断搜索引擎蜘蛛爬虫还是人为访问代码

时间:2024-02-07 17:07:01

相关推荐

php 判断爬虫程序 php判断搜索引擎蜘蛛爬虫还是人为访问代码

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 '人';

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。