Quantcast
Viewing latest article 4
Browse Latest Browse All 8

Answer by Peter for Struggling with recaptcha v2 and form submission

Using curl instead of file_get_contents (should you, like me, want file_get_contents to be disabled in the server settings)

$post_data = "secret=__your_secret_key__&response=".
   $_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR'] ;

$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, 
   array('Content-Type: application/x-www-form-urlencoded; charset=utf-8', 
   'Content-Length: ' . strlen($post_data)));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
$googresp = curl_exec($ch);       
$decgoogresp = json_decode($googresp);
curl_close($ch);

if ($decgoogresp->success == true)
    {
    // Success
    }

Viewing latest article 4
Browse Latest Browse All 8

Trending Articles