只允许搜索引擎蜘蛛访问屏蔽用户访问的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()){
Header("Location: //www.zuimoban.com/");
exit();
}
?>
(责任编辑:最模板)以上可以放在网站html代码中,前提让主机html支持php解析,可以在.htaccess加入如下代码: AddType application/x-httpd-php .html .htm |