Google reCaptcha 2.0 not working, is it for curl?
after several tries (Explicitly rendering), I finally show it reCaptcha
on my website.
Inside the tag <head></head>
.
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
and inside my form
<form action="" method="post">
<input placeholder="Enter Your Name" type="text" required/>
<input placeholder="Enter Your Email" type="email" required/>
<input placeholder="Enter Your Password" type="password" required/>
<div class="g-recaptcha" data-sitekey="My_reCaptcha_Site_Key"></div>
<?php echo $msg; ?>
<input type="submit" value="Register">
</form>
and my php
code
<?php
$msg='';
if($_SERVER["REQUEST_METHOD"] == "POST"){
$recaptcha=$_POST['g-recaptcha-response'];
if(!empty($recaptcha)){
include 'getCurlData.php';
$google_url="https://www.google.com/recaptcha/api/siteverify";
$secret='My_reCaptcha_Secret_Key';
$ip=$_SERVER['REMOTE_ADDR'];
$url=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
$res=getCurlData($url);
$res= json_decode($res, true);
//reCaptcha success check
if($res['success']){
$msg="Your reCAPTCHA succeeded.";
} else {
$msg="Please re-enter your reCAPTCHA 1.";
}
} else {
$msg="Please re-enter your reCAPTCHA 2.";
}
}
?>
and my getCurlData.php
code is like
<?php
function getCurlData($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
$curlData = curl_exec($curl);
curl_close($curl);
return $curlData;
}
?>
I have given you all the details that I have tried. But the problem is that reCaptcha
it failed. So it shows a checkmark, but it $msg
shows "Please re-enter your RECAPTCH 1." I cannot find the error.
For your information, I am testing it at localhost
, and if successful, I will upload it to my hosting site GoDaddy
.
I found this procedure but didn't work.
Update:
According to Stretch I tried
$res=file_get_contents($url);
instead
getCurlData($url);
And the problem is solved. However, I am opening my own question.
So there is no need curl
? Why should we use curl
in reCaptcha
?
source to share
The reason it doesn't work is because you are trying to access HTTPS. The solution you shouldn't use is this:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
The solution you should use is the following:
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');
fooobar.com/questions/88044 / ... has a link to the latest version of cacert.pem.
source to share