php - Google reCaptcha 2.0 not working, Is it for curl? -


after several trying (explicitly render), show recaptcha in website.

inside <head></head> tag..

<script src="https://www.google.com/recaptcha/api.js" async defer></script> 

and inside form

<form action="" method="post">     <input placeholder="enter name" type="text" required/>     <input placeholder="enter email" type="email" required/>     <input placeholder="enter 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 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 recaptcha 1.";         }     } else {         $msg="please re-enter recaptcha 2.";     } } ?> 

and getcurldata.php code 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 entire details i've tried. problem is, recaptcha not succeeded. means, showing tick mark $msg showing "please re-enter recaptcha 1." unable find error.

for information, testing in localhost, , if succeeded, upload in godaddy hosting site.

i have found this procedure, not worked.

update:

as per stretch, tried

$res=file_get_contents($url); 

instead of

getcurldata($url); 

and problem solved. putting question open.

so there no need of curl ? why should use curl in recaptcha ?

the reason it's not working because you're trying access https. solution shouldn't use this:

curl_setopt($ch, curlopt_ssl_verifypeer, false); 

the solution should use this:

curl_setopt($ch, curlopt_cainfo, 'cacert.pem'); 

https://stackoverflow.com/a/316732/364841 has link latest cacert.pem.