· 4 years ago · Dec 11, 2020, 11:40 AM
1<?php
2
3if(isset($_POST['g-recaptcha-response'])){
4 $captcha=$_POST['g-recaptcha-response'];
5}
6
7if(!$captcha){
8 echo '<h2>Please check the the captcha form.</h2>';
9 exit;
10}
11
12$secretKey = "Put your secret key here";
13
14function verifyCaptcha($secretKey){
15 $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) . '&response=' . urlencode($captcha);
16 $response = file_get_contents($url);
17 $responseKeys = json_decode($response,true);
18 // should return JSON with success as true
19 if($responseKeys["success"]) {
20 echo 'Success';
21 } else {
22 echo 'Failed';
23 }
24}
25
26
27 ?>