无法验证ReCAPCHA 2

时间:2019-02-08 21:41:07

标签: verification

我在工作的HTML表单中添加了google ReCAPCHA 2。我正在使用一个php文件来验证ReCAPCHA并将邮件内容寄出。 ReCAPCHA未在验证,谷歌说“我们检测到您的网站未在验证reCAPTCHA解决方案。这是在您的网站上正确使用reCAPTCHA所必需的。”无论是否在表单上使用ReCAPACHA,都将通过邮件发送表单。

我不确定为什么,我检查了密钥并且它们正确无误,以下是我在PHP文件中用于验证ReCapcha的内容:

$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
    'secret' => 'my_secret_key_is_inserted_here ',
    'response' => $_POST["g-recaptcha-response"]
);
$options = array(
    'http' => array (
        'header' => 'Content-Type: application/x-www-form-urlencoded',
        'method' => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
    echo "<p>You are a bot! Go away!</p>";
} else if ($captcha_success->success==true) {
    echo "<p>Your submission succeeded. Thank you!</p>";

}

0 个答案:

没有答案