頁面瀏覽次數統計

echo '</p>'; function is_valid_page($page) { $page = str_replace(":", "/", $page); return is_file(getcwd() . "/data/pages/" . $page . ".txt"); } if (empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $myip = $_SERVER['REMOTE_ADDR']; } else { $myip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $myip = $myip[0]; } $myip = explode('.', $myip); if (($myip[0] == 140) && ($myip[1] == 114) && ($myip[2] == 64)) { $REC = array(); $PATH = "/tmp/dokuwiki-viewcount"; if (is_dir($PATH)) { if ($dh = opendir($PATH)) { while (($file = readdir($dh)) !== false) { $filename = "$PATH/$file"; if (is_file($filename) && is_valid_page($file)) { $REC[$file] = file_get_contents($filename); } } closedir($dh); } } arsort($REC); echo '<table class="inline">'; echo "<tr><th>頁面名稱</th><th>瀏覽次數</th></tr>\n"; foreach ($REC as $key => $val) { if ($key == "viewcount") { continue; } echo "<tr><td>$key</td><td>$val</td></tr>\n"; } echo '</table>'; } echo '<p>';