Visitor counting with bot exclusion

This commit is contained in:
Christopher Teutsch 2020-12-27 19:08:21 +01:00
parent 1a41d23667
commit 9478c7cecd

View File

@ -63,8 +63,8 @@ $ical->initUrl($ICAL_URL, $acceptLanguage = 'de');
$events = $ical->eventsFromInterval('2 week'); $events = $ical->eventsFromInterval('2 week');
$first_event = $events[0]; $first_event = $events[0];
$events = array_slice($events, 1); $events = array_slice($events, 1);
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']); $locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
if ($locale !== null){
setlocale(LC_TIME, $locale); setlocale(LC_TIME, $locale);
} }
} }
@ -178,6 +178,27 @@ $v = file_get_contents($VISITORS_FILE);
</body> </body>
</html> </html>
<?php <?php
/* Initialising values */
if(!$v) $v=0; if(!$v) $v=0;
$count_visit = true;
/* List of bots I found in various access logs */
$invalid_uas = array(
"AhrefsBot",
"Googlebot",
"Yahoo",
"Go-http-client/",
"bingbot",
"CheckMarkNetwork",
"SemrushBot",
"BingPreview",
"facebookexternalhit",
);
foreach ($invalid_uas as $ua){
if(stripos($_SERVER['HTTP_USER_AGENT'], $ua) !== FALSE){
$count_visit = false;
}
}
if ($count_visit === TRUE){
$v++; $v++;
file_put_contents($VISITORS_FILE, $v); file_put_contents($VISITORS_FILE, $v);
}