なリンクが貼られるので /public_html/ref.phpとかにおいて $dir = '../webalizer/'; if ( ! is_dir($dir) ) { die('no valid dir'); } // ファイル名を得る $files = array(); $dh = opendir($dir); while ( FALSE !== ($file = readdir($dh)) ) { if ( ! preg_match('/^usage_\d{4}\d{2}\.html$/', $file, $m) ) { continue; } array_push($files, $m[0]); } closedir($dh); rsort($files, SORT_STRING); // 表示設定 if ( empty($files) || ! is_array($files) ) { ob_start(); header('HTTP/1.1 404'); echo('no referer data'); header('Content-Length: '.ob_get_length()); ob_end_flush(); exit(); } elseif ( isset($_GET['year']) && is_numeric($_GET['year']) && isset($_GET['month']) && is_numeric($_GET['month']) ) { $filename = $dir. 'usage_'. $_GET['year']. $_GET['month']. '.html'; if ( ! file_exists($filename) ) { ob_start(); header('HTTP/1.1 404'); echo('file not found'); header('Content-Length: '.ob_get_length()); ob_end_flush(); exit(); } ob_start(); header('Content-Type: text/html; charset=Shift_JIS'); header('Cache-Control: no-cache'); header('Pragma: no-cache'); if ( $buf = get_referers($filename) ) { echo $buf; } else { echo 'no referrer'; } header('Content-Length: '.ob_get_length()); ob_end_flush(); } else { ob_start(); header('Content-Type: text/html; charset=Shift_JIS'); header('Cache-Control: no-cache'); header('Pragma: no-cache'); echo render_files($files); header('Content-Length: '.ob_get_length()); ob_end_flush(); } exit(); function render_files(&$files) { $html = <<<_EOF_