web トップページ (index.html) の設定など¶
TOPページからのリダイレクト¶
ディレクトリ構成¶
public_html
|
---- index.html (toppage)
|
---- Docs/ (sphinx files , eg. index.html )
|
---- msc/
といった構成にする場合、トップページからのリダイレクトを設定する.下記の通り.
リダイレクト ( .html )¶
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; URL=Docs/index.html" />
<title>Redirecting...</title>
</head>
<body>
<p>Redirecting to <a href="Docs/index.html">documentation</a>...</p>
</body>
</html>
メモアプレット¶
メモを記載する掲示板webアプリを作成.
php ファイル¶
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Paste Board</title>
</head>
<body>
<h1>My Paste Board</h1>
<form method="POST">
<textarea name="content" rows="10" cols="80" placeholder="Paste your content here..."></textarea><br>
<input type="submit" value="Post">
</form>
<form style="text-align: left; margin-bottom: 10px;">
<button type="button" onclick="location.reload();" style="padding: 5px 10px;">
🔄 Update
</button>
</form>
<hr>
<h2>Posts (latest 3 days)</h2>
<div style="white-space: pre-wrap;">
<?php
date_default_timezone_set('Asia/Tokyo');
// ---- 古いファイルを削除(3日以上前) ----
$files = glob("log_*.txt");
$now = time();
foreach ($files as $file) {
if (preg_match("/log_(\d{4}-\d{2}-\d{2})\.txt/", $file, $matches)) {
$date = $matches[1];
$timestamp = strtotime($date);
if ($now - $timestamp > 60 * 60 * 24 * 1) { // ←ここが3日に
unlink($file);
}
}
}
// ---- 投稿保存 ----
if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST["content"])) {
$today = date('Y-m-d');
$entry = "[" . date('H:i:s') . "]\n" . $_POST["content"] . "\n\n";
$filename = "log_" . $today . ".txt";
$old = file_exists($filename) ? file_get_contents($filename) : '';
file_put_contents($filename, $entry . $old, LOCK_EX);
}
// ---- 表示:最新のファイル順で読み込み ----
$files = glob("log_*.txt");
rsort($files);
foreach ($files as $file) {
echo "<h3>" . htmlspecialchars(str_replace(['log_', '.txt'], '', $file)) . "</h3>";
$content = file_get_contents($file);
echo htmlspecialchars($content, ENT_QUOTES, 'UTF-8');
echo "<hr>";
}
?>
</div>
</body>
</html>