Powered By Blogger

Thursday, August 29, 2019

google re captcha server side validation OR Verifying the user's response by API



https://developers.google.com/recaptcha/docs/verify


 $recaptcha = $_POST['g-recaptcha-response'];

if (!empty($recaptcha)) {
$captcha = array(
'secret' => 'secret key',
'response' => $recaptcha,
);

$getpage= 'https://www.google.com/recaptcha/api/siteverify';
$c = curl_init($getpage);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $captcha);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);


$html = curl_exec($c);
curl_close($c);

$gapi_res = json_decode($html);
}

No comments:

Post a Comment