一个简单的 Bot识别与流量过滤示例项目。
用于演示如何识别:
- 爬虫
- 机器人
- 自动访问工具
从而保护网站正常访问流量。
很多网站都会遇到:
- 爬虫抓取
- 恶意扫描
- 自动化访问
- 机器人点击
这些访问会影响:
- 网站统计数据
- 服务器资源
- 广告流量质量
示例系统包含:
- UserAgent识别
- Bot检测
- 访问过滤
- 简单访问控制
<?php
function isBot(){
$bots=[
"googlebot",
"bingbot",
"spider",
"crawler",
"bot"
];
$ua=strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');
foreach($bots as $b){
if(strpos($ua,$b)!==false){
return true;
}
}
return false;
}
if(isBot()){
echo "Bot detected";
}else{
echo "Real visitor";
}
?>流量过滤
Bot识别
反机器人
广告流量安全
访问控制