這是本文件的舊版!
<?php
global $ID;
$counter_dir = DOKU_CONF . 'pagecounters/';
if (!is_dir($counter_dir)) {
@mkdir($counter_dir, 0755, true);
}
$counter_file = $counter_dir . md5($ID) . '.txt'; $count = file_exists($counter_file) ? (int)file_get_contents($counter_file) : 0;
// Increment only for real users
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (!preg_match('/bot|crawl|spider|slurp|pingdom|semrush|ahrefs|mj12bot|googlebot/i', $ua)) {
$count++;
file_put_contents($counter_file, $count);
}
echo 'Views: ' . number_format($count); ?>
<?php
global $ID;
$counter_dir = DOKU_CONF . 'pagecounters/';
if (!is_dir($counter_dir)) {
@mkdir($counter_dir, 0755, true);
}
$counter_file = $counter_dir . md5($ID) . '.txt'; $count = file_exists($counter_file) ? (int)file_get_contents($counter_file) : 0;
// Increment only for real users
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (!preg_match('/bot|crawl|spider|slurp|pingdom|semrush|ahrefs|mj12bot|googlebot/i', $ua)) {
$count++;
file_put_contents($counter_file, $count);
}
echo 'Views: ' . number_format($count); ?>