Mel*_*Dog 6 php captcha recaptcha
我正在尝试在我的网站上实施谷歌新的'NoCaptcha'.到目前为止,我的小部件看起来很好,但它在我的PHP页面上没有验证.
我的代码设置如下:
在 <head>
<script src='https://www.google.com/recaptcha/api.js'></script>
Run Code Online (Sandbox Code Playgroud)
客户端:
<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>
Run Code Online (Sandbox Code Playgroud)
服务器端(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
}
Run Code Online (Sandbox Code Playgroud)
我试过回声,$_POST['g-recaptcha-response']
但看起来很空洞.这就像变量没有发布到php.
有谁知道我在做错了什么?
您的代码使用我自己的私钥/公钥在我的测试服务器上运行良好。这看起来微不足道,但我必须添加的唯一一件事 - 您的其他表单输入中是否有提交按钮?这实际上是将数据发送到 PHP 脚本的。
<input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
否则,添加var_dump($_POST['g-recaptcha-response']);
到您的 bookingverify.php 并查看它输出的内容。
归档时间: |
|
查看次数: |
7101 次 |
最近记录: |