Recaptcha missing-input-response

Please note : g-recaptcha-respone != g-recaptcha-response

enter image description here

enter image description here

Google reCatcha API you might need to specify additional parameters to the file_get_contents function call, setting the context options specifically for SSL (If site has SSL).

// If submitted check response
if ($_POST["g-recaptcha-response"]) {

// Input data
$secret = 'SECRET_KEY';
$response = $_POST['g-recaptcha-response'];
$remoteip = $_SERVER['REMOTE_ADDR'];

$url = "https://www.google.com/recaptcha/api/siteverify";

$post_data = http_build_query(
    array(
        'secret' => $secret,
        'response' => $response,
        'remoteip' => $remoteip
    )
);  

$options=array(

    // If site has SSL then
    'ssl'=>array(

        // In my case its /etc/ssl/certs/cacert.pem

        'cafile'            => '/path/to/cacert.pem',
        'verify_peer'       => true,
        'verify_peer_name'  => true,
    ),

   'http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $post_data
    )
);

$context = stream_context_create( $options );   

$result_json = file_get_contents( $url, false, $context );
$resulting = json_decode($result_json, true);

if($resulting['success']) {
    //Success
} else {
     // action for no response 
}

At least on ubuntu - If site has SSL

cd /usr/local/share/ca-certificates 
sudo curl http://curl.haxx.se/ca/cacert.pem -o cacert.crt 
sudo update-ca-certificates
sudo update-ca-certificates –fresh

and your cafile and path will be

capath=/etc/ssl/certs/
cafile=/etc/ssl/certs/cacert.pem

In my case I needed to add two extra parameters ('', '&') in this call:

http_build_query(array(
    'secret' => $secret,
    'response' => $response,
    'remoteip' => $remoteip
), '', '&');

Tags:

Php

Recaptcha