輕量級 PHP 靜態站點生成器:管理員登入 → 文章編輯(FCKeditor) → 靜態 HTML 生成 → 索引頁自動更新。核心邏輯僅需 4 個檔案與目錄寫入權限。
session.php:管理員身份驗證getip.php:客戶端 IP 取得(輔助驗證)html.php:統一入口(登入/發文/生成)templates/article.tpl:文章頁面模板data/index.txt:文章索引(檔名|標題|時間)// 1. 組裝完整 HTML 字串
$html = file_get_contents('templates/article.tpl');
$html = str_replace('{TITLE}', $_POST['title'], $html);
$html = str_replace('{CONTENT}', $_POST['content'], $html);
// 2. 檔名採時間戳確保唯一
$filename = date('YmdHis') . '.html';
file_put_contents("articles/$filename", $html);
// 3. 更新索引檔(預置新行)
$indexLine = "$filename|{$_POST['title']}|" . date('Y-m-d H:i:s') . "\n";
file_put_contents('data/index.txt', $indexLine . file_get_contents('data/index.txt'));
$lines = file('data/index.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$listHtml = '';
foreach ($lines as $line) {
[$file, $title, $time] = explode('|', $line);
$listHtml .= "<li><a href='articles/$file'>$title</a> <span>$time</span></li>";
}
$indexTpl = file_get_contents('templates/index.tpl');
$indexTpl = str_replace('{LIST}', $listHtml, $indexTpl);
file_put_contents('index.html', $indexTpl);
array_chunk 分組生成 index-1.html、index-2.htmlcategory-xxx.html