<?php
// локальная страница проверки reCAPTCHA
header('Content-Type: text/javascript; charset=UTF-8');
header('Expires: Thu, 18 Aug 1994 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Access-Control-Allow-Methods: GET');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: *');
header('X-Robots-Tag: noindex');

require_once(__DIR__.'/data/conf.php');

$token = isset($_GET['token']) ? trim(strip_tags($_GET['token'])) : die('var score = 0;');
$ip = isset($_GET['ip']) ? trim(strip_tags($_GET['ip'])) : die('var score = 0;');

$params = [
    'secret' => $ab_config['recaptcha_secret'],
    'response' => $token,
    'remoteip' => $ip
];
$CurlHandle = curl_init('https://www.google.com/recaptcha/api/siteverify');
curl_setopt($CurlHandle, CURLOPT_POST, 1);
curl_setopt($CurlHandle, CURLOPT_POSTFIELDS, $params);
//curl_setopt($CurlHandle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($CurlHandle, CURLOPT_HEADER, 0);
curl_setopt($CurlHandle, CURLOPT_TIMEOUT, 7);
curl_setopt($CurlHandle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($CurlHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($CurlHandle, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($CurlHandle, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($CurlHandle, CURLOPT_ENCODING, 'gzip');
$response = curl_exec($CurlHandle);
$arr = json_decode($response, true);
if (isset($arr['score'])) {
echo 'var score = '.trim($arr['score']).';';
} else {
echo 'var score = 0;';
}
