验证码的PHP代码无法正常工作

时间:2018-04-21 12:09:02

标签: forms validation captcha

我一直尝试使用以下代码,但没有任何显示,请帮助我做错了。我是非常新的php,所以请寻求你的帮助。

<?php
    if(!isset($_SESSION["$first_num"])) {
        $_SESSION["$first_num"] = rand(1,10); 
    }
    if(!isset($_SESSION["$second_num"])) {
        $_SESSION["$second_num"] = rand(1,10); 
    }
    $operators = array("+", "-", "*");
    $operator = rand(0, count($operators) -1);
    $operator = $operators [$operator];
    $answer = 0;
    switch ($operator) {
    case "+"
    $answer = $first_num + $second_num;
    break;
    case "-":
    $answer = $first_num - $second_num;
    break;
    case "*":
    $answer = $first_num * $second_num;
    break;
    }
    $_SESSION["answer"] = $answer;
    ?>
    <?php
    $answer = $_SESSION["answer"];
    $user_answer = $_POST["answer"];
    if ($answer == $user_answer) {
    echo "Form Submitted Successfully"
    } else {
    echo "Incorrect Captcha try again"
    ?>

0 个答案:

没有答案