mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-11 14:10:06 +01:00
cleanup: quick cleanup of bot checking code
This commit is contained in:
parent
e78b800c64
commit
3e44d88ed8
2 changed files with 12 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Add table
Reference in a new issue