<?php
    $min  = 1;
    $max  = 10;
    $num1 = rand( $min, $max );
    $num2 = rand( $min, $max );
?>
<!DOCTYPE html>
<html>

<head>
    <title>Math recaptcha</title>
    <link rel="stylesheet" 
          href="style.css" 
          type="text/css">
</head>

<body>
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h3>
        Creating a Simple Math CAPTCHA form using PHP
    </h3>
    <div class="container">
        <form method="POST">
            Name: <input type="text" 
                         name="name" 
                         autocomplete="off"
                         required><br>
            Email: <input type="text" 
                          name="email" 
                          autocomplete="off" 
                          required><br>
            <div class="col-12">
                <div class="row">
                    <div class="col-md-6">
                        <div class="row">
                            <label for="quiz" 
                                   class="col-sm-3 col-form-label">
                                <?php echo $num1 . '+' . $num2; ?>
                            </label>
                            <div class="col-sm-9">
                                <input type="hidden" 
                                       name="no1" 
                                       value="<?php echo $num1 ?>">
                                <input type="hidden"
                                       name="no2" 
                                       value="<?php echo $num2 ?>">
                                <input type="text" 
                                       name="test"
                                       class="form-control quiz-control" 
                                       autocomplete="off"
                                       id="quiz" required>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <input type="submit"
                   name="submit" 
                   id="submit">
        </form>
        <?php
            if(isset($_REQUEST["submit"]))
            {
                $test=$_REQUEST["test"];
                $number1=$_REQUEST["no1"];
                $number2=$_REQUEST["no2"];
                $total=$number1+$number2;
                if ($total==$test)
                {
                    header("Location: welcome.php");
                    exit();
                }
                else {
                    echo "<p>
                                <font color=red 
                                    font face='arial' 
                                    size='5pt'>
                                Invalid captcha entered !
                                </font>
                            </p>";
                     }
            }
        ?>
    </div>
</body>

</html>