Visitor counting with bot exclusion
This commit is contained in:
parent
1a41d23667
commit
9478c7cecd
31
index.php
31
index.php
@ -63,8 +63,8 @@ $ical->initUrl($ICAL_URL, $acceptLanguage = 'de');
|
||||
$events = $ical->eventsFromInterval('2 week');
|
||||
$first_event = $events[0];
|
||||
$events = array_slice($events, 1);
|
||||
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
if ($locale !== null){
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
||||
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
setlocale(LC_TIME, $locale);
|
||||
}
|
||||
}
|
||||
@ -178,6 +178,27 @@ $v = file_get_contents($VISITORS_FILE);
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
if(!$v) $v=0;
|
||||
$v++;
|
||||
file_put_contents($VISITORS_FILE, $v);
|
||||
/* Initialising values */
|
||||
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++;
|
||||
file_put_contents($VISITORS_FILE, $v);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user