验证reCAPTCHA时提交注册表格

问题描述 投票:0回答:2

我在注册表格中添加了reCAPTCHA,并且在测试页面时,我注意到我仍然可以注册新帐户而无需使用reCAPTCHA进行验证。当我将其中一个文本框留为空白时,我会收到“请确认您是人类”。当用户填写表单而忘记验证时,该消息应该会出现。如果堆栈溢出和其他网站提供的语句,我尝试了许多不同的方法,但问题仍然没有解决。我还尝试用“方法”和“动作”弄乱我的表单。

这是我的注册表

<?php include('server.php') ?>
<!DOCTYPE html>
<html>
<head>
    <title>Register for Redchan</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
    <a href="index.php" title="Home"><img alt="4chan" src="/image/pepe-popcorn.gif" width="300" height="120"></a>
    <div class="header">
        <h2>Register for Redchan</h2>
    </div>
    <?php
    //Check for form submission
    if ($_SERVER['REQUEST_METHOD'] == "POST")
    {
        //Get form submission data
        $username = $_POST['username'];
        $email = $_POST['email'];


        //Set verification information for the Google reCAPTCHA API
        $secretKey = "----------------------------------";
        $responseKey = $_POST['g-recaptcha-response'];
        $userIP = $_SERVER['REMOTE_ADDR'];

        //Call Google reCAPTCHA API
        $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
        $response = file_get_contents($url);

        //Decode API response and generate response
        $verification = json_decode($response, true);
        if ($verification['success'])
            echo "<p>Verification success!</p>";
        else
            echo "<p>Please verify that you are a Human.</p>";
    }
?>
    <form method="post" action="register.php">

        <?php include('errors.php'); ?>

        <div class="input-group">
            <label>Username</label>
            <input type="text" name="username" value="<?php echo $username; ?>">
        </div>
        <div class="input-group">
            <label>Email</label>
            <input type="email" name="email" value="<?php echo $email; ?>">
        </div>
        <div class="input-group">
            <label>Password</label>
            <input type="password" name="password_1">
        </div>
        <div class="input-group">
            <label>Confirm password</label>
            <input type="password" name="password_2">
        </div>
        <div class="g-recaptcha" data-sitekey="-------------------------------"></div>
        <div class="input-group">
            <button type="submit" class="btn" name="reg_user">Register</button>
        </div>
        <p>
            Already a member? <a href="login.php">Sign in</a>
        </p>
    </form>
</body>
</html>
php recaptcha
2个回答
1
投票

您需要将验证码字段本身设置为必填字段,默认情况下不是。

您可以尝试这样的事情:

<script type="text/javascript">
    window.onload = function() {
        var $recaptcha = document.querySelector('#g-recaptcha-response');

        if ($recaptcha) {
            $recaptcha.setAttribute("required", "required");
        }
    };
</script>

0
投票

感谢您的回复,香港专业教育学院尝试过此

window.onload = function(){var $ recaptcha = document.querySelector('#g-recaptcha-response');

if ($recaptcha) {
    $recaptcha.setAttribute('#free_play_form_button').click()
}

};

但表格未回应

正在使用篡改猴子,我是否添加了正确的篡改方法?

© www.soinside.com 2019 - 2024. All rights reserved.