【发布时间】:2015-02-25 08:17:17
【问题描述】:
我正在尝试在我的网站上实施 Google 的新“NoCaptcha”。到目前为止,我的小部件看起来很好,但它没有在我的 PHP 页面上验证。
我的代码是这样设置的:
在<head>
<script src='https://www.google.com/recaptcha/api.js'></script>
客户端:
<form id="contactform" action="bookingverify.php" method="POST">
<input type="text" name="name" size="41">
<!--OTHER FORM INPUTS-->
<div class="g-recaptcha" data-sitekey="mypublickey"></div>
</form>
服务器端(bookingverify.php)
$captcha;
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=myprivatekey&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false){
echo '<h2>You are spammer</h2>';
}
else{
//SEND MAIL
}
我尝试回显$_POST['g-recaptcha-response'],但它显示为空。就像那个变量没有被发布到 php 中一样。
有人知道我在这里做错了什么吗?
【问题讨论】: