From 8ee2160c6b871bce130df4de28a39985cdc43ad2 Mon Sep 17 00:00:00 2001 From: German Correa Date: Thu, 7 Sep 2017 14:19:07 -0300 Subject: [PATCH] Add captcha server side valdation to contact.php script --- contact.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/contact.php b/contact.php index 251cb1f..760be04 100644 --- a/contact.php +++ b/contact.php @@ -1,4 +1,22 @@ '6LeLxy4UAAAAABClplWLJUjZ1_nhX_-SI7CuNcm8', + 'response' => $_POST["g-recaptcha-response"] + ); + $options = array( + 'http' => array ( + 'header' => 'Content-Type: application/x-www-form-urlencoded\r\n', + 'method' => 'POST', + 'content' => http_build_query($data) + ) + ); + $context = stream_context_create($options); + $verify = file_get_contents($url, false, $context); + $captcha_success=json_decode($verify); + return $captcha_success; +} // process.php $errors = array(); // array to hold validation errors @@ -16,6 +34,13 @@ $data = array(); // array to pass back data if (empty($_POST['mensage'])) $errors['mensage'] = 'Mensaje is required.'; + if(empty($_POST['g-recaptcha-response'])){ + $errors['recaptcha'] = 'Debe validar el captcha'; + } + else if(!verifyCaptcha()){ + $errors['recaptcha'] = 'Error en la validaciĆ³n de ReCaptcha'; + } + // return a response =========================================================== // if there are any errors in our errors array, return a success boolean of false @@ -48,4 +73,4 @@ $data = array(); // array to pass back data // return all our data to an AJAX call echo json_encode($data); -?> \ No newline at end of file +?>