| 1 |
<?php |
| 2 |
class AccuaForm_Validation_Captcha2b extends Validation { |
| 3 |
protected $message = "Error: The reCATPCHA response provided was incorrect. Please re-try."; |
| 4 |
protected $privateKey; |
| 5 |
|
| 6 |
public function isValid($value) { |
| 7 |
if (!isset($_POST['g-recaptcha-response'])) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
$response = stripslashes_deep($_POST['g-recaptcha-response']); |
| 12 |
|
| 13 |
if ($response === '') { |
| 14 |
return false; |
| 15 |
} |
| 16 |
|
| 17 |
$url = 'https://www.google.com/recaptcha/api/siteverify' |
| 18 |
.'?secret='.urlencode($this->privateKey) |
| 19 |
.'&response='.urlencode($response) |
| 20 |
.'&remoteip='.urlencode($_SERVER["REMOTE_ADDR"]); |
| 21 |
|
| 22 |
$ch = curl_init(); |
| 23 |
curl_setopt($ch, CURLOPT_URL, $url); |
| 24 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 25 |
curl_setopt($ch, CURLOPT_TIMEOUT, 20); |
| 26 |
$res = curl_exec($ch); |
| 27 |
curl_close($ch); |
| 28 |
|
| 29 |
if ($res !== false) { |
| 30 |
@ $res = json_decode($res, true); |
| 31 |
if (!empty($res['success'])) { |
| 32 |
return true; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
return false; |
| 37 |
} |
| 38 |
} |
| 39 |
|