| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle Recaptcha |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Frontend\Recaptcha; |
| 8 |
|
| 9 |
Class Google_Recaptcha_Handler{ |
| 10 |
|
| 11 |
/** |
| 12 |
* Response G- Recaptcha |
| 13 |
* |
| 14 |
* @param string $secretKey |
| 15 |
* @param $token |
| 16 |
* |
| 17 |
* @since 2.5.5 |
| 18 |
*/ |
| 19 |
public static function get_response_recaptcha( $secretKey = '', $token ){ |
| 20 |
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR']: null; |
| 21 |
$url = "https://www.google.com/recaptcha/api/siteverify"; |
| 22 |
$data = array('secret' => $secretKey, 'response' => $token, 'remoteip'=> $ip); |
| 23 |
|
| 24 |
$query = http_build_query($data); |
| 25 |
$options = array( |
| 26 |
"ssl"=>array( |
| 27 |
"verify_peer"=>false, |
| 28 |
"verify_peer_name"=>false, |
| 29 |
), |
| 30 |
'http' => array( |
| 31 |
'header' => "Content-Type: application/x-www-form-urlencoded\r\n". |
| 32 |
"Content-Length: ".strlen($query)."\r\n". |
| 33 |
"User-Agent:MyAgent/1.0\r\n", |
| 34 |
'method' => "POST", |
| 35 |
'content' => $query, |
| 36 |
), |
| 37 |
); |
| 38 |
$context = stream_context_create($options); |
| 39 |
$result = file_get_contents($url, false, $context); |
| 40 |
return json_decode($result); |
| 41 |
} |
| 42 |
} |
| 43 |
|