Answer the question
In order to leave comments, you need to log in
Why does recapcha always say you are a robot?
recapcha always returns false, what's the problem?
if (isset($_POST['token']) && isset($_POST['action'])) {
$captcha_token = $_POST['token'];
$captcha_action = $_POST['action'];
} else {
die('Капча работает некорректно. Обратитесь к администратору!');
}
$url = 'https://www.google.com/recaptcha/api/siteverify';
$params = [
'secret' => '6Lfwl4MUAAAAAKCP8ZV13J6ngN_A9RiPtzxM9CDi',
'response' => $captcha_token,
'remoteip' => $_SERVER['REMOTE_ADDR']
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if(!empty($response)) $decoded_response = json_decode($response);
$success = false;
if ($decoded_response && $decoded_response->success && $decoded_response->action == $captcha_action && $decoded_response->score > 0) {
$success = $decoded_response->success;
// обрабатываем данные формы, которая защищена капчей
} else {
// прописываем действие, если пользователь оказался ботом
}
echo json_encode($success);
$('.ofert_button').on('click', function(e) {
e.preventDefault();
grecaptcha.ready(function() {
grecaptcha.execute('6Le9e48UAAAAAI4pZF-AENNFk_g-bE4Yez6AHnue', {action: 'homepage'}).then(function(token) {
var action = 'homepage';
var token = '6Le9e48UAAAAAI4pZF-AENNFk_g-bE4Yez6AHnue';
var fio = $('.form_dogovor input[name=fio]').val();
var address = $('.form_dogovor input[name=address]').val();
var email = $('.form_dogovor input[name=email]').val();
var sum = $('.form_dogovor input[name=sum]').val();
var ofert = 1;
var phone = $('.form_dogovor input[name=phone]').val();
$.ajax({
url: '/ofert.php',
method: 'POST',
dataType: 'text',
data: {ofert, fio, address, email, sum, phone, action, token}
}).done(function(data) {
alert(data);
});
});
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question