时间:2021-07-01 10:21:17 帮助过:4人阅读
define('ISROBOT', getrobot());
if(defined('NOROBOT') && ISROBOT) {
exit(header("HTTP/1.1 403 Forbidden"));
}
function getrobot() {
if(!defined('IS_ROBOT')) {
$kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
$kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';
if(preg_match("/($kw_browsers)/", $_SERVER['HTTP_USER_AGENT'])) {
define('IS_ROBOT', FALSE);
} elseif(preg_match("/($kw_spiders)/", $_SERVER['HTTP_USER_AGENT'])) {
define('IS_ROBOT', TRUE);
} else {
define('IS_ROBOT', FALSE);
}
}
return IS_ROBOT;
}