properly compare user agent against user agent array

This commit is contained in:
Joe 2022-03-21 15:58:33 -05:00
parent 038e250527
commit 8fed9cb2e4
Signed by: joe
GPG Key ID: 8595A3F8F2CE1B74
1 changed files with 4 additions and 2 deletions

View File

@ -41,8 +41,10 @@ class ImageViewCounter extends Extension
// Don't add view for common crawler user agents
$ua = $_SERVER["HTTP_USER_AGENT"] ?? "No UA";
$ua_arr = ['googlebot', 'yandexbot', 'yandex', 'petalbot', 'baiduspider', 'bingbot', 'msnbot', 'semrushbot', 'dataforseobot', 'dotbot', 'rogerbot', 'slurp', 'duckduckbot', 'sogou', 'exabot', 'facebot', 'facebook', 'ia_archiver', 'applebot'];
if (in_array(strtolower($ua), $ua_arr)) {
return;
foreach($ua_arr as $ua_part) {
if (str_contains(strtolower($ua), $ua_part)) {
return;
}
}
// Add view for current IP