recaptcha总是不正确的PHP和bootstrap

时间:2014-04-24 06:54:37

标签: php twitter-bootstrap captcha recaptcha

我正在为我的网站创建一个登录页面。我使用标准recaptcha来验证新帐户,但我的recaptcha总是回来不正确。我已经尝试了所有"标准" stackoverflow上列出的修复程序。我的代码中没有表(使用bootstrap 3.x),今天我从google服务器中提取了recaptcha.php文件,它有API的新位置。我不知道为什么会这样做。我已经检查过,并且检查了我的代码,但公开和私人。

任何帮助都会很棒。这是两段代码。首先,在我的index.php页面上:

            Register:
        <form class="navbar-form navbar-left" role="search" action="php/verify.php" >

            <div class="input-group">
                <span class="input-group-addon">Username</span>
                <input type="text" name="username" class="form-control" placeholder="Username" >
            </div>

            <div class="input-group">
                <span class="input-group-addon">Email</span>
                <input type="text" name="email" class="form-control" placeholder="Email">
            </div>

            <div class="input-group">
                <span class="input-group-addon">Password</span>
                <input type="password" name="password" class="form-control" placeholder="Password">
            </div>

            <?php
              require_once('php/recaptchalib.php');
              $publickey = "xxxxxxxxxxxxxxxx-changed for security"; // you got this from the signup page
              echo recaptcha_get_html($publickey);
            ?>

            <button type="submit" value="Register" class="btn btn-default">Submit</button>
        </form>

然后,这是它进入的verify.php文件:

  require_once('recaptchalib.php');
  $privatekey = "xxxxxxxxxxxxxx-changed for safety";
  $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
            $message = "Your CAPTCHA was wrong, please retry.";
            echo "<script type='text/javascript'>
                    alert('$message');
                    window.location = '../';
                  </script>";

  } 
  else {
            $message2 = "Your CAPTCHA was right!!";
            echo "<script type='text/javascript'>
                    alert('$message2');
                    window.location = '../';
                  </script>";
  }

0 个答案:

没有答案