User Agent过滤器有时仅在“ strpos”中起作用

问题描述 投票:0回答:1

我只想过滤掉所有Facebook爬虫,以便它们不会出现在即将发布的统计信息中,但是在我检查了数据库记录后,我仍然找到了一些Facebook爬虫(我使用的是Cloudflare防火墙,而我只允许使用Facebook爬虫,所有其他爬虫被其他用户代理阻止)

我不确定“ strpos”是否正确?

if (strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)") === false &&          
    strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/1.1") === false){

$database->query("INSERT INTO `phits` (`type`, `user_id`, `date`, `ip`) VALUES ('profile', {$profile_account->user_id}, '{$date}', '{$ip}')"); 

}
php filter user-agent
1个回答
0
投票
if (strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)") !== false || strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/1.1") !== false || strpos($_SERVER["HTTP_USER_AGENT"], "Mediapartners-Google") !== false){ } else{ $database->query("INSERT INTO `phits` (`type`, `user_id`, `date`, `ip`) VALUES ('profile', {$profile_account->user_id}, '{$date}', '{$ip}')"); }
© www.soinside.com 2019 - 2024. All rights reserved.