我的重新验证码不起作用



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

感谢您的帮助。

如果您有更好的脚本,请发送给我。

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>";
}

我在处理验证码时使用 ReCaptcha 包用于作曲家。

如果你不知道作曲家是什么,我建议你去 http://composer.org/

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

验证码包:https://packagist.org/packages/google/recaptcha

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

以下是我在服务器上处理Google重新验证码的方式:

//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-urlencodedrn",
'method'  => 'POST',
'content' => http_build_query($data)
)
);
$context  = stream_context_create($options);
$result = json_decode(file_get_contents($url, false, $context),TRUE);
return $result;
}

最新更新