我的重新CAPTCHA不起作用

时间:2017-08-22 14:10:41

标签: php

我在我的网站上使用重新验证,但是当我点击登录时它不起作用说机器人验证失败,请再试一次我不知道如何解决它...每次:/

感谢您的帮助。

如果你有更好的剧本请发给我。

        if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response']))
    {
        $secret = '**************';

        $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
        $responseData = json_decode($verifyResponse);

        if($responseData->success)
        { 

        }else{
                echo "<div class='container'><div class='alert alert-danger'><p>Robot verification failed, please try again.</p></div>";
            }
    }else{
            echo "<div class='container'><div class='alert alert-danger'><p>Please click on the reCAPTCHA box.</p></div>";
    }

2 个答案:

答案 0 :(得分:0)

以下是我在服务器上处理Google Re-Captcha的方法:

//process captia response with a custom method.
$captcha = checkCaptia($_POST['g-recaptcha-response']);

if ($captcha){
    mailLead();
}
else{
   header('location: https://...');
   die();
}

处理验证码检查的方法......

function checkCaptia($captcha){ 
    $url = 'https://www.google.com/recaptcha/api/siteverify';

    $data = array(
        'secret'=>';jaskdf;asdkjf',
        'response'=>$captcha,
        'remoteip'=>$_SERVER['REMOTE_ADDR']
    );

    $options = array(
        'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
        )
    );
    $context  = stream_context_create($options);
    $result = json_decode(file_get_contents($url, false, $context),TRUE);

    return $result;
}

答案 1 :(得分:0)

在处理验证码时,我使用ReCaptcha包作为Composer。

如果您不知道Composer是什么,我建议您前往http://composer.org/

Composer是一个PHP依赖项管理器,在构建现代PHP应用程序时非常有用。

ReCaptcha套餐:https://packagist.org/packages/google/recaptcha

代码示例也包含在链接中。

相关问题