-
Notifications
You must be signed in to change notification settings - Fork 1
/
captcha.php
42 lines (36 loc) · 1.12 KB
/
captcha.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
function ConfirmHuman($key) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$fields = array(
'secret' => $key,
'response' => $_REQUEST['g-recaptcha-response']
);
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$json = curl_exec($ch);
//close connection
curl_close($ch);
$result = json_decode($json);
if ($result->success == true) {
return true;
}
else {
print '<h3>Unable to process your request</h3>'.PHP_EOL;
foreach ($result->{'error-codes'} as $error) {
if ($error == 'missing-input-response') {
print '<li class="warn">Be sure to check the "I'm not a robot" box below</li>'.PHP_EOL;
}
else { print '<li class="warn">'.$error.'</li>'.PHP_EOL; }
}
}
}
?>