None of my new 'NoCaptchas' are working! I've lost hours of time and money trying to have this work!

388 views
Skip to first unread message

Radian W

unread,
Dec 29, 2014, 1:01:43 AM12/29/14
to reca...@googlegroups.com
Sorry but this is driving me insane! I simply cannot spend much longer trying to working this out. This new Captcha has put me so far behind on my schedule.

So here's what I have tried:

Ive put the link to the JS file in my <head> as normal:


and placed the code in my form:

<form id="contactform" action="verify.php" method="POST">
<input type="text" name="name" size="41">
<!--OTHER FORM INPUTS-->
<div id="captchaholder">
<div class="g-recaptcha" data-sitekey="6LcPYPwSAAAAAMhDW_9k8WBMBrHbbJ50UEq20Yji"></div>
</div><!--CAPTCHAHOLDER-->


Thats fine - the Captcha widget appears.

The problem is I cannot get anything on the PHP side to work.

I have tried 2 ways on doing this:

Attempt 1:
$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
  }
Attempt 2:
if($_SERVER["REQUEST_METHOD"] == "POST") { $recaptcha=$_POST['g-recaptcha-response']; if(!empty($recaptcha)) { echo "not empty";include("getCurlData.php");
$google_url
="https://www.google.com/recaptcha/api/siteverify";
$secret
='secretKey';
$ip
=$_SERVER['REMOTE_ADDR'];
$url
=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
$res
=getCurlData($url);
$res
= json_decode($res, true);
if($res['success'])
{
//SEND MAIL
}


In both cases neither script worked. It was like $_POST['g-recaptcha-response'] was empty in each.

Can anyone, for the love or code, tell me what on Earth I am doing wrong here (and why, oh why, have Googled supplied next to no documentation???)?

Many thanks in advance

kh99

unread,
Dec 29, 2014, 2:47:44 AM12/29/14
to reca...@googlegroups.com
In your first attempt, $response.success is wrong. You should do json_decode() like in your second attempt.  I can't see what's wrong in the second attempt (although I'm not familiar with using curl). Are you saying you never see the 'not empty' echo?
Reply all
Reply to author
Forward
0 new messages