我试图让谷歌验证码工作,但它不会,它总是失败说“错误的验证码请再试一次!”。谁能看到我是否在任何地方做错了什么?
PHP
if(isset($_POST)){
$captcha=$_POST['g-recaptcha-response'];
$ip = $_SERVER['REMOTE_ADDR'];
$secretkey = "4444444444444444444444444444";
$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) {
echo '<h2>Wrong captcha try again please!</h2>';
exit;
} else {
echo '<h2>Success!</h2>';
exit;
}
}
HTML
<form id="regerform" method="post" action="register.php" class="form">
<div class="third">
<div class="thirdLast">
<label for="username">
<?php echo t("username", "username"); ?>:
</label>
<input type="text" tabindex="3" value="<?php echo isset($username) ? safeOutputToScreen($username) : ''; ?>" id="username" name="username">
</div>
<div class="clear"></div>
<div class="g-recaptcha" data-sitekey="4444444444444444444444444444"></div>
</form>