时间:2021-07-01 10:21:17 帮助过:6人阅读
function isAllowAccess($directForbidden = FALSE) {
$allowed = array('/baiduspider/i', '/googlebot/i');
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$valid = FALSE;
foreach ($allowed as $pattern) {
if (preg_match($pattern, $user_agent)) {
$valid = TRUE;
break;
}
}
if (!$valid && $directForbidden) {
exit("404 not found");
}
return $valid;
}
在要禁止访问的页面头部引用这个函数来做判断就ok了,如下俩中调用方式:
代码如下:
if (!isAllowAccess()) {
exit("404 not found");
}
//或者
isAllowAccess(TRUE);