<?php
session_start();
// 初回訪問時は訪問回数を0に初期化
if (!isset($_SESSION["visit_count"])) {
$_SESSION["visit_count"] = 0;
}
// 訪問回数を増やす
$_SESSION["visit_count"]++;
$count = $_SESSION["visit_count"];
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>訪問カウンター</title>
<style>
body {
font-family: sans-serif;
max-width: 600px;
margin: 50px auto;
padding: 20px;
text-align: center;
}
.counter {
font-size: 48px;
color: #4CAF50;
margin: 30px 0;
}
button {
background-color: #2196F3;
color: white;
padding: 12px 30px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin: 10px;
}
button:hover {
background-color: #0b7dda;
}
.reset {
background-color: #f44336;
}
.reset:hover {
background-color: #da190b;
}
</style>
</head>
<body>
<h1>訪問カウンター</h1>
<div class="counter"><?php echo $count; ?>回目の訪問</div>
<p>このページにアクセスした回数が記録されています。</p>
<p>ページをリロードすると回数が増えます。</p>
<form method="post" action="counter.php">
<button type="submit">リロード</button>
</form>
<form method="post" action="reset.php">
<button type="submit" class="reset">カウンターをリセット</button>
</form>
</body>
</html>