-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptchaAuth.php
More file actions
59 lines (36 loc) · 1.36 KB
/
captchaAuth.php
File metadata and controls
59 lines (36 loc) · 1.36 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/*
Recaptcha library including Curl functions
*/
class Recaptcha {
private $secret = "jshfjashfuogbaobfahfsduo9230";//fake key for demo purpose
public function check()
{
$code = $_POST['g-recaptcha-response'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=".$this->secret."&response=".$code."&remoteip=".$_SERVER['REMOTE_ADDR'];
$response = $this->get($url);
$resp_a = json_decode($response, true);
return (isset($resp_a['success']) ? $resp_a['success'] : false);
}
private function get($url) {
$curl_handle = curl_init($url);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl_handle,CURLOPT_TIMEOUT, 5);
$return_data = curl_exec($curl_handle);
curl_close($curl_handle);
return $return_data;
}
private function post($url,$data) {
$curl_handle = curl_init($url);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($curl_handle,CURLOPT_TIMEOUT, 5);
curl_setopt($curl_handle,CURLOPT_POST, true);
curl_setopt($curl_handle,CURLOPT_POSTFIELDS, $data);
$return_data = curl_exec($curl_handle);
curl_close($curl_handle);
return $return_data;
}
}
?>