diff --git a/includes/common.php b/includes/common.php index ffb16b4..eba2532 100644 --- a/includes/common.php +++ b/includes/common.php @@ -170,10 +170,7 @@ function pp_html_escape(string $unescaped) : string { return htmlspecialchars($unescaped, ENT_QUOTES, 'UTF-8', false); } -/* I think there is one row for each day, and in that row, tpage = non-unique, tvisit = unique page views for that day */ -function updatePageViews() : void { - global $redis; - +function isRequesterLikelyBot() : bool { $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : ''; // Don't count bots @@ -181,6 +178,17 @@ function updatePageViews() : void { || str_contains($userAgent, 'bot') || str_contains($userAgent, 'spider') || str_contains($userAgent, 'crawl')) { + return true; + } + + return false; +} + +/* I think there is one row for each day, and in that row, tpage = non-unique, tvisit = unique page views for that day */ +function updatePageViews() : void { + global $redis; + + if (isRequesterLikelyBot()) { return; } diff --git a/public/paste.php b/public/paste.php index 472ff91..17822bd 100644 --- a/public/paste.php +++ b/public/paste.php @@ -8,10 +8,6 @@ use PonePaste\Models\Paste; use PonePaste\Models\User; use PonePaste\Pastedown; -function isRequesterLikelyBot() : bool { - return str_contains(strtolower($_SERVER['HTTP_USER_AGENT']), 'bot'); -} - function rawView($content, $p_code) : void { if ($p_code) { header('Content-Type: text/plain');