我只是用复选框设置了新的google recaptcha,它在网站端工作正常,但是我不知道如何在服务器端使用php进行操作,我尝试使用下面的旧代码,但即使是不使用recaptcha.
require_once('recaptchalib.php');
$privatekey = "my key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$errCapt='<p style="color:#D6012C ">The CAPTCHA Code wasnot entered correctly.</p>';}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的网站上实施谷歌新的'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.
有谁知道我在做错了什么?
我试图在我的网站上使用reCaptcha,并且recaptcha_challenge_field和recaptcha_response_field没有被添加到后端的$ _POST数组中 - 但是我的表单中的其余变量是.
有任何想法吗?我仔细检查了公钥/私钥.
这是生成的HTML:
<form action='myform.php' name='myform' id='myform' method='post' enctype='multipart/form-data'>
<tr class='select'>
<td class='label'>Name:</td>
<td>
<input type='text' name='name' id='name' class='inputtext' maxlength='25' size='25' >
</td>
</tr>
<tr class='select'>
<td class='label'>Email:</td>
<td>
<input type='text' name='email' id='email' class='inputtext' maxlength='25' size='25' >
</td>
</tr>
<tr class='select'>
<td class='label'>Message:</td>
<td>
<textarea class='inputtext' name='message' rows='10' cols='45'></textarea>
</td>
</tr>
<tr class='select'>
<td class='label'>Are you human?</td>
<td>
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=MY_KEY"></script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=MY_KEY" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>
</td> …Run Code Online (Sandbox Code Playgroud)