我的html表单看起来像这样:
<form method="post" action="mail.php" name="contactform" id="contactform">
<div class="input-wrap"><i class="fa fa-user-plus" aria-hidden="true"></i><input name="name" type="text" id="name" class="inputForm2" onClick="this.select()" value="Name" ></div>
<div class="input-wrap"><i class="fa fa-envelope" aria-hidden="true"></i><input name="email" type="text" id="email" onClick="this.select()" value="E-mail" ></div>
<textarea name="comments" id="comments" onClick="this.select()">Message</textarea>
<div class="g-recaptcha" data-sitekey="--- SITE KEY FROM GOOGLE ---" style="float: right"></div>
<textarea name="g-recaptcha-response" id="g-recaptcha-response" style="display: none"></textarea>
<button type="submit" id="submit"><span>Send Message</span></button>
</form>
我有这样的mail.php:
$url = 'https://www.google.com/recaptcha/api/siteverify';
$secretkey = "--- SECRET KEY FROM GOOGLE ---";
$response = file_get_contents($url."?sectret=".$secretkey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
$data = json_decode($response);
if(isset($data->success) AND $data->success == false){
//error
exit;
}else{
//success
}
我无法弄清问题在哪里!如果有人可以帮助我吗?
如果我echo
$data
,如果我检查验证码表单,我总是会收到{ "success": false, "error-codes": [ "missing-input-response", "missing-input-secret" ] }
无关紧要的情况。我不知道为什么在显示的错误中给我,也就是"missing-input-secret"
当我给他秘密密钥时...... {/ p>
答案 0 :(得分:1)
你这里有一个错字:
$response = file_get_contents($url."?sectret=".$secretkey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
应该是:
$response = file_get_contents($url."?secret=".$secretkey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);