如何处理谷歌的reCAPTCHA与jquery?

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

我需要对谷歌验证码提供一些信息。我要抢在我在我的jQuery文件下插入captcha.php文件比较“G-reCAPTCHA的响应”的值,然后使用jquery $。员额()方法将其发送到captcha.php文件。我道歉,如果这是重复的,但我真的不能找人跟我同样的问题;)

在HTML

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="generator" content="AlterVista - Editor HTML"/>
    <script src='https://www.google.com/recaptcha/api.js'></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="handle_spam.js" type="text/javascript"></script>
    <title></title>
</head>
<body>

    <div class="g-recaptcha" data-sitekey="6Lf8LxIUAAAAALg93pw24l53KTeqrIwl7kUY-opk"></div>
    <button id="go">Register</button>

</body>
</html>

PHP的

<?php
    $captcha=$_POST['g-recaptcha-response'];
    echo $captcha;       
    if(!$captcha){
        echo 'You must verify yourself';
        exit;
    }
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Lf8LxIUAAAAACB9iqeOermR-rPOW0zcWRfoetBO&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
    if($response.success==false)
    {
        echo 'abort_all';
    }else
    {
        echo 'success';
    }
?>

THE JS

$(document).ready(function(){
    $('#go').click(function(){
        send=$('')
        $.post('captcha.php',function(data){
            alert(data);
        });
    });
});
javascript php jquery recaptcha
1个回答
1
投票

用这个

<div class="g-recaptcha" data-callback="captchaCallback" data-sitekey="...">

并提供以下功能:

function captchaCallback(response) {
    alert(response);
}
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.