reCAPTCHA failed in file_get_contents

2

I'm trying to increment a reCAPTCHA on a website, I've watched several step by step, but mine persists in giving the same error. example code:

index.php
<html xmlns="http://www.w3.org/1999/html">
    <head>
        <title>index</title>
        <script src='https://www.google.com/recaptcha/api.js'></script>
    </head>
    <body>
         <form method="post" action="verify.php">
             <input type="text" name="inp"/></br>
             <div class="g-recaptcha" data-sitekey="********************"></div>
             <input type="submit"></br>
         </form>
    </body>
</html>

verify.php

<?php
header("Content-type: text/php charset=utf-8");
if(isset($_POST['g-recaptcha-response'])&& $_POST['g-recaptcha-response']){
     var_dump($_POST);
     //informações sobre o reCAPTCHA
     $secret = "**************************************************";
     var_dump($secret);
     $ip = $_SERVER['REMOTE_ADDR'];
     var_dump($_SERVER);
     $captcha =  $_POST['g-recaptcha-response'];
     var_dump($captcha);
     //Enviar para o google
     $rps = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$captcha&remoteip$ip");
     //resposta google
     var_dump($rps);
    // $arr = json_decode($rsp,true)
  }else{
     echo "reCAPTCHA não prenchido";
}

The error always occurs in

 $rps = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$captcha&remoteip$ip");

The var_dump($rps); should return "success": true but always returns

  

Warning : file_get_contents () [function.file-get-contents]: URL   file-access is disabled in the server configuration in    /home/storage/2/8a/81/necon1/public_html/verify.php on line    13

    
asked by anonymous 07.04.2017 / 16:28

1 answer

-1

Some servers disable the use of file_get_contents, in other words, google has blocked any access from file_get_contents. You can use PHP's cURL to bypass the lock. In case, your code would look like this:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$captcha&remoteip$ip");
curl_setopt($ch, CURLOPT_HEADER, 0);


$rps = curl_exec($ch);

//print da resposta do google
echo "<pre>"
print_r($rps);

curl_close($ch);

Click here to access the cURL manual.

    
07.04.2017 / 16:57