title: Codeigniter reCaptcha v3 with cUrl
body: <p>I have a form integrated with invisible reCaptcha.</p>
  
  <p>Verification is performed on a function within the Controller.</p>
  
  <p>The call to google is made using file_get_content and if no response is obtained, the call is made using curl.</p>
  
  <p>This is the function</p>
  
  <pre><code>public function verify_captcha()
          {
  
              $recaptcha_response = $_POST['recaptchaResponse'];
  
              log_message('info', $recaptcha_response);           
  
              // Build POST request:
  
              $recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify'; 
              $recaptcha_secret = 'My KEY'; 
              $recaptcha_response = $_POST['recaptchaResponse']; 
              $recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&amp;response=' . $recaptcha_response); 
              $recaptcha = json_decode($recaptcha,true);      
  
  
              if(!$recaptcha)
              {
                  // call curl to POST request
  
                  log_message('info', 'Call CURL');       
                  $data = array( 'secret' =&gt; $recaptcha_secret, 'response' =&gt; $recaptcha_response); 
                  //$curlConfig = array( CURLOPT_URL =&gt; $recaptcha_url, CURLOPT_POST =&gt; true, CURLOPT_RETURNTRANSFER =&gt; true, CURLOPT_POSTFIELDS =&gt; $data ); 
                  $ch = curl_init(); 
  
                  curl_setopt($ch, CURLOPT_URL,  $recaptcha_url);
                  curl_setopt($ch, CURLOPT_POST, true);
                  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);             
  
                  $response = curl_exec($ch);                 
  
                  curl_close($ch);
                  $recaptcha = json_decode($response, true);  
  
  
                  ob_start();
                  var_dump($recaptcha);
                  $result = ob_get_contents(); //or ob_get_clean()
                  log_message('info', $result);               
  
  
  
                  if (array_key_exists('error-codes', $recaptcha))
                  {
  
                      log_message('error',  'Error reCaptcha '.$recaptcha['error-codes'][0]);
  
                  }               
  
  
  
                  if ($recaptcha["success"] == '1') 
                  { 
                      if ($recaptcha["score"] &gt;= 0.5) 
                      {
  
                      }
                  }
                  else
                  {
                    log_message('error',  'Error reCaptcha no Success');
                  }
         else
         {
           log_message('info', 'Call file_get_content');
         }    
  }
  </code></pre>
  
  <p>These are the messages of the log file</p>
  
  <pre><code>ERROR - 2020-03-18 09:54:31 --&gt; Severity: Warning  --&gt; file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known /mysite/application/controllers/captcha.php 1362
  ERROR - 2020-03-18 09:54:31 --&gt; Severity: Warning  --&gt; file_get_contents(https://www.google.com/recaptcha/api/siteverify?secret=6LfP26QUAAAAAHilJfguEgIcgOBkTg2soD7oCQIh&amp;amp;response=03AERD8XpOL7956DMd7dhiqasH4fK2iNjtBFBJdw3OynXGeAFBMmSqqtjsqXFW97rv-kD_H-y6aLrL1VLMkwg222Y7BoNnaB_zQ7y2NzXVtlIsWYwIw9BSbUdFdSylq4dNjO5j5Jo1xvjPotvMFuddnC5YVRC1wnk7HESqv8hvRU40x9pNpoQ-sIaXcAN8BdBgleXFufmmNoMzuh3PCvgT3RkIj1TsTs-ltM9LyVbLtFnFPbTkHZqpQjppMkHCcw87u3xqbr23EJkusR_U2vFwJTAJU9p-Z27sDuiKmEMsjJ2O1i3Wnxm9yq4HiEI2vnh420VDnPZEYRbXuLLSGhGuPciGQ3mtp07tjn265oyYbcFp2s9GentdUpPWRCxWfySTa6du7dzzSHkqPMKcPf6LmfVtICkTJf4y-w): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known /mysite/application/controllers/captcha.php 1362
  INFO  - 2020-03-18 09:54:31 --&gt; Call CURL
  INFO  - 2020-03-18 09:54:31 --&gt; NULL
  </code></pre>
  
  <p>The call to file_get_content shows error and returns nothing with curl.</p>
  
  <p>What may be happening?</p>
  
  <p>Thanks</p>