reCAPTCHA 2实施不适用于我的网站?

时间:2018-09-10 14:24:41

标签: forms recaptcha

很长一段时间以来,我在我的网站上的表单都能正常工作。但是我面临着来自机器人的大量垃圾邮件,从而导致通过我的管理员发送电子邮件。因此,我想实现一个reCAPTCHA 2。

但是它不起作用:每次访问https://www.google.com/recaptcha/api/siteverify时,成功都会保持'false'

当我现在访问我的网站时,按F11键也会出现以下错误:

  

未捕获的referenceerror $未定义:$(document).ready(function(){

当我填写表单并单击“发送”时,即使没有签名“我不是机器人”框,它也会刷新页面。

这是我的代码: public_html / submit.php

<?php
$secret = $_POST["secret"];
$response = $_POST["response"];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$response;
$verify = file_get_contents($url);
echo $verify;
?>

public_html / contact.php

<html lang="en">
    <head>
        <?php include_once("php/sitetag.php"); ?>
        <title>Empire of the Wicked: Contact</title>
        <link rel="stylesheet" type="text/css" href="css/style0.css">
        <?php include_once("php/meta.php"); ?>
        <script src='https://www.google.com/recaptcha/api.js'></script>
    </head>
    <body>
        <?php include_once("scripts/analyticstracking.php") ?>
        <div id="container">
            <header>
                <?php include_once("php/header.php"); ?>
            </header>
            <nav>
                <?php include_once("php/nav.php"); ?>
            </nav>
            <main>
    <h2>Submit your game review:</h2>
    <table><tr><td>
    <form class="game-review recaptchaForm" method="post">
        <div class="form-group">
        Name* (will be published with your review):<br><input type="text" name="name1" size="50" maxlength="50" required/>
        </div>
        <br><br>
        <div class="form-group">
        E-mail (hidden with your review):<br><input type="text" name="email1" size="50" maxlength="50"/>
        </div>
        <br><br>
        <div class="form-group">
            <div class="g-recaptcha" data-sitekey="****************************************************"></div>
        </div>
            <br><br>
        <div class="form-group">
            <button type="submit" class="btn btn-default">Submit</button>
        </div>
        </form>
        </td></tr></table>

        <script>
    $(document).ready(function() {
        $(".recaptchaForm").submit(function(event) {
            var recaptcha = $("#g-recaptcha-response").val();
            if (recaptcha === "") {
                event.preventDefault();
                alert("Please check the recaptcha");
            }
             event.preventDefault();
                $.post("submit.php",{
                    "secret":"*******************************************",
                    "response":recaptcha
                },function(ajaxResponse){
                    console.log(ajaxResponse);
                    });     

        });
    });
    </script>
                </main>
                <footer>
                    <?php include_once("php/footer.php"); ?>
                </footer>
            </div>
        </body>
    </html>

0 个答案:

没有答案