· 7 years ago · Sep 24, 2018, 08:04 PM
1google-recaptcha-verfication.php
2<?php
3$ch = curl_init();
4
5// TODO - Define your SafetyNet Secret in the below line
6$secretKey = 'Place your SafetyNet Secret here';
7$captcha = isset($_POST['recaptcha-response']) && !empty($_POST['recaptcha-response']) ? $_POST['recaptcha-response']: '';
8
9curl_setopt_array($ch, [
10 CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
11 CURLOPT_POST => true,
12 CURLOPT_POSTFIELDS => [
13 'secret' => $secretKey,
14 'response' => $captcha,
15 'remoteip' => $_SERVER['REMOTE_ADDR']
16 ],
17 CURLOPT_RETURNTRANSFER => true
18]);
19
20$output = curl_exec($ch);
21curl_close($ch);
22
23$json = json_decode($output);
24$res = array();
25
26if($json->success){
27 $res['success'] = true;
28 $res['message'] = 'Captcha verified successfully!';
29}else{
30 $res['success'] = false;
31 $res['message'] = 'Failed to verify captcha!';
32}
33
34echo json_encode($res);
35?>