上传文件至 src
This commit is contained in:
commit
d4f95b998c
103
src/index.php
Normal file
103
src/index.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['correct_count'])) {
|
||||
$_SESSION['correct_count'] = 0;
|
||||
}
|
||||
|
||||
if ($_SESSION['correct_count'] >= 10) {
|
||||
echo "Congratulations! You are clever. Here is your flag: FLAGFLAGFLAG";
|
||||
exit();
|
||||
}
|
||||
|
||||
function generateQuestion() {
|
||||
$nums = [];
|
||||
$operators = ['+', '-', '*', '/'];
|
||||
|
||||
for ($i = 0; $i < 9; $i++) {
|
||||
$nums[] = rand(1000000, 99999999);
|
||||
}
|
||||
|
||||
$expression = "{$nums[0]}";
|
||||
for ($i = 1; $i < count($nums); $i++) {
|
||||
$operator = $operators[array_rand($operators)];
|
||||
$expression .= " $operator {$nums[$i]}";
|
||||
}
|
||||
|
||||
// 确保除数不为0
|
||||
if (strpos($expression, '/ 0') !== false) {
|
||||
return generateQuestion(); // 重新生成题目
|
||||
}
|
||||
|
||||
// 计算答案
|
||||
try {
|
||||
$answer = eval("return ($expression);");
|
||||
if (is_float($answer)) {
|
||||
$answer = round($answer, 2);
|
||||
}
|
||||
} catch (DivisionByZeroError $e) {
|
||||
return generateQuestion(); // 处理除以0的情况
|
||||
}
|
||||
|
||||
$_SESSION['answer'] = $answer;
|
||||
return $expression;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
if (isset($_POST['hiahia'])) {
|
||||
$userAnswer = trim($_POST['hiahia']);
|
||||
$correctAnswer = $_SESSION['answer'];
|
||||
|
||||
// 处理浮点数比较
|
||||
if (abs(floatval($userAnswer) - floatval($correctAnswer)) < 0.01) {
|
||||
$_SESSION['correct_count'] += 1;
|
||||
if ($_SESSION['correct_count'] >= 10) {
|
||||
echo "Congratulations! You are clever. Here is your flag: FLAGFLAGFLAG";
|
||||
exit();
|
||||
} else {
|
||||
$message = "Correct! Keep going! You have answered {$_SESSION['correct_count']} correctly.";
|
||||
}
|
||||
} else {
|
||||
$_SESSION['correct_count'] = 0;
|
||||
$message = "Wrong answer or time out! Try again.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$question = generateQuestion();
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="refresh" content="3"> <!-- 将刷新时间改为3秒 -->
|
||||
<title>Advanced Math Challenge</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
margin-top: 50px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Give me your answer for 3 seconds:</h1> <!-- 文案也改成3秒 -->
|
||||
<h2><?php echo $question; ?> ?</h2>
|
||||
|
||||
<?php if (isset($message)) : ?>
|
||||
<p><?php echo $message; ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST">
|
||||
<input type="text" name="hiahia" autofocus autocomplete="off" required>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user