<?php
session_start();
// フォームから送信されたかチェック
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
header("Location: question.php");
exit;
}
// ユーザーの答えを取得
$userAnswer = $_POST["answer"] ?? "";
// Sessionから正解を取得
$correctAnswer = $_SESSION["current_answer"] ?? "";
$question = $_SESSION["current_question"] ?? "";
// 正誤判定
$isCorrect = ($userAnswer === $correctAnswer);
?>
<!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;
}
.result-container {
background: white;
padding: 30px;
border-radius: 8px;
border: 1px solid #ddd;
text-align: center;
}
.correct {
color: #4CAF50;
font-size: 48px;
margin: 20px 0;
}
.incorrect {
color: #f44336;
font-size: 48px;
margin: 20px 0;
}
.message {
font-size: 24px;
margin: 20px 0;
}
.detail {
font-size: 16px;
color: #666;
margin: 20px 0;
}
a {
display: inline-block;
margin-top: 20px;
padding: 12px 30px;
background-color: #2196F3;
color: white;
text-decoration: none;
border-radius: 4px;
}
a:hover {
background-color: #0b7dda;
}
</style>
</head>
<body>
<div class="result-container">
<?php if ($isCorrect): ?>
<div class="correct">🎉</div>
<div class="message">正解です!</div>
<div class="detail">
問題: <?php echo htmlspecialchars($question); ?><br>
あなたの答え: <?php echo htmlspecialchars($userAnswer); ?>
</div>
<?php else: ?>
<div class="incorrect">😢</div>
<div class="message">残念!不正解です。</div>
<div class="detail">
問題: <?php echo htmlspecialchars($question); ?><br>
あなたの答え: <?php echo htmlspecialchars($userAnswer); ?><br>
正解: <?php echo htmlspecialchars($correctAnswer); ?>
</div>
<?php endif; ?>
<a href="question.php">もう一度挑戦する</a>
</div>
</body>
</html>