Google recaptcha error (Warning: file_get_contents(http://www.google.com/recaptcha/api/siteverify?secret)

1,641 views
Skip to first unread message

NJ Mudin

unread,
Dec 22, 2015, 2:20:47 AM12/22/15
to reCAPTCHA
Guys....

I have a problem when using google recaptcha v.2.0 . i really confused when installing google recaptcha in my php
this is the simple code :

$nama = isset($_POST['nama'])?trim(htmlentities($_POST['nama'])):'';
$komentar = isset($_POST['pj'])?trim(htmlentities($_POST['pj'])):'';
/* untuk menampung variabel post dari captcha google adalah g-recaptcha-reponse */
$captcha = isset($_POST['g-recaptcha-response'])?$_POST['g-recaptcha-response']:'';
//masukkan secret key-nya berdasarkan secret key masig-masing saat create api key nya
$secret_key = xxx'; 
$error = 'Gagal kirim form: periksa nama, komentar dan captcha nya';
if($captcha != '' && $nama != '' && $komentar != '') {
   
 
$recaptcha = file_get_contents($url);
  $recaptcha = json_decode($recaptcha, true);
  if(!$recaptcha['success']) {
 
  //echo $error;
  echo "<script type=\"text-javascript\">alert($error)</script>";
 
  }else {
     
      echo 'Nama Anda : '.$nama.'<br>Komentar Anda : '.$komentar;
  }
 
}else {
  
  echo "<script>alert('$error')</script>";
  //echo $error;
}

X

unread,
Dec 22, 2015, 4:43:40 AM12/22/15
to reCAPTCHA
Hi, your warning message that you have placed in this issue title is truncated, but I will assume it says:

"failed to open stream"

In this case you need to enable it in php.ini

"allow_url_fopen = On"

or use CURL fallback function.
Reply all
Reply to author
Forward
0 new messages