<?php

if(isset($_POST['g-recaptcha-response']))
{$captcha=$_POST['g-recaptcha-response'];}

$captcha_ok=0;
// if(!$captcha){echo 'Please check the the captcha form.';exit;}

$secretKey = "6LdlxwkUAAAAAGaUI53C8Oa2seEvZ7pvQCPBVvR0";

if($_SERVER['SERVER_NAME']=='www.ecuataxi.com')
{$secretKey = "6Ld1XzIkAAAAAMISJHK3H8T15YwfY3U5quwBs40O";}

// echo '*/*/*/*'.$_SERVER['SERVER_NAME'].'+-+-+-'.$secretKey;

$ip = $_SERVER['REMOTE_ADDR'];
// post request to server
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) .  '&response=' . urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response,true);
// should return JSON with success as true
// if($responseKeys["success"])
// {echo 'Thanks for posting comment';}
// else {echo 'You are spammer ! Get the @$%K out';}

if($responseKeys["success"]){$captcha_ok=1;}
else {$captcha_ok=2;}


return;

define("RECAPTCHA_V3_SECRET_KEY", '6LdXALciAAAAABvvpXJpN51IUrr5vWh1ndgdC6M6');
$token = $_POST['token'];
$action = $_POST['action'];
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('secret' => RECAPTCHA_V3_SECRET_KEY, 'response' => $token)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$arrResponse = json_decode($response, true);
 

$dom = new DOMDocument();
     $dom->encoding = 'utf-8';
     $dom->xmlVersion = '1.0';
     $dom->formatOutput = true;

$response=$dom->appendChild($dom->createElement("response"));
if($arrResponse["success"] == '1' and $arrResponse["action"] == $action and $arrResponse["score"] >= 0.5)
{
     // Si entra aqui, es un humano, puedes procesar el formulario
     // 	echo "ok!, eres un humano";
     $result=$response->appendChild($dom->createElement("result","OK")); 
     $result->setAttribute("id","recaptcha");
     $recaptcha=1;
}else{
     // Si entra aqui, es un robot....
     // 	echo "Lo siento, parece que eres un Robot";
     $result=$response->appendChild($dom->createElement("result","Error")); 
     $result->setAttribute("id","recaptcha");
     $recaptcha=0;
}

echo $dom->saveXML();
// return $dom->saveXML();

?>
