谷歌reCAPTCHA在本地工作但不在我的服务器上工作

时间:2018-01-24 16:02:51

标签: recaptcha

我有一个表格,需要勾选谷歌reCAPTCH。它完全适用于Local,但是当我把它放在开发服务器上时它不起作用。我已将注册密钥替换为Google指定给我的密钥。

它不断输出错误信息。

我的表单中的方法是post。

我不明白为什么它不起作用。有人可以帮帮我吗?

这是我的代码:

        $secretKey = "#######";
        $captcha = $_POST['g-recaptcha-response'];

        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);

        if(intval($responseKeys["success"]) !== 1) {
            $throwErrorMessage = "You are a robot! ";
            $throwError = 1;
            $isvalid = False;
       };

1 个答案:

答案 0 :(得分:0)

您使用的是什么版本的ReCAPTCHA? Google网站here上的文档与您的代码完全不同。特别是,您在文档使用recaptcha_check_answer时使用函数 <?php require_once('recaptchalib.php'); $privatekey = "your_private_key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again."."(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification } ?> ,如下例所示:

inspect.getcallargs

您可以发布错误消息吗?

相关问题