From d4f95b998cbda7f1db3e8b411a35f2cfd538e211 Mon Sep 17 00:00:00 2001 From: jiangsir <1463310682@qq.com> Date: Wed, 11 Sep 2024 21:56:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20src?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.php | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/index.php diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..f313bf1 --- /dev/null +++ b/src/index.php @@ -0,0 +1,103 @@ += 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(); + +?> + + + + +
+ + +