Answer the question
In order to leave comments, you need to log in
Need help setting up reCaptcha v3beta on the server side, can you tell me what's wrong?
I'm trying to set up reCaptcha v3beta on the submit form, but nothing comes out, at least it doesn't show statistics. Or perhaps everything works, but there are no statistics due to the fact that there is little traffic.
Link to the site with the form:
www.kwoonfan.h1n.ru/recaptcha0
Site code:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>reCaptcha</title>
<link rel="stylesheet" href="css/main.css">
<script src='https://www.google.com/recaptcha/api.js?render=6LehUWUUAAAAAKu51NyhKOjmhz3XEGC4xTyH85-u'></script>
</head>
<body>
<div id="wrapper">
<form action="send.php" method="post" id="form">
<input type="text" placeholder="Name" name="fio">
<input type="tel" placeholder="Phone" name="phone">
<div class="btn_cover">
<button class="btn">ORDER</button>
</div>
</form>
</div>
<script src="js/main.js"></script>
</body>
</html>
#wrapper {
display: flex;
justify-content: center;
align-items: center;
height: 800px;
width: 100%;
}
#form {
padding: 30px;
background-color: orangered;
border-radius: 4px;
}
input {
width: 100%;
height: 40px;
font-size: 20px;
box-sizing: border-box;
margin: 10px 0;
padding-left: 20px;
outline: none;
border-radius: 4px;
}
.btn_cover {
width: 100%;
text-align: center;
padding: 20px 0;
}
.btn {
padding: 20px 30px;
font-size: 20px;
margin: 0 auto;
min-width: 200px;
cursor: pointer;
border-radius: 4px;
}
grecaptcha.ready(function () {
grecaptcha.execute('ТУТ МОЙ СЕКРЕТНЫЙ КОД', {
action: 'login'
})
.then(function (token) {
...
});
});
<?php
$fio = $_POST['fio'];
$phone = $_POST['phone'];
$fio = htmlspecialchars($fio);
$phone = htmlspecialchars($phone);
$fio = urldecode($fio);
$phone = urldecode($phone);
$text = urldecode($text);
$fio = trim($fio);
$phone = trim($phone);
$text = trim($text);
//echo $fio;
//echo "<br>";
//echo $email;
if (mail("ТУТ МОЯ ПОЧТА, КУДА ПРИХОДЯТ ПИСЬМА", "Заявка с сайта", "ФИО:".$fio.". Phone:".$phone. "From: KWOONFAN \r\n"))
{ echo "сообщение успешно отправлено";
} else {
$gipadress=$_SERVER['REMOTE_ADDR'];
$grecaptcha=$_POST['g-recaptcha-response'];
$postdata = http_build_query(
array(
'secret' => 'ТУТ МОЙ СЕКРЕТНЫЙ КОД',
'response' => $grecaptcha,
'remoteip' => $gipadress
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$gcontents = stream_context_create($opts);
$gresults = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $gcontents);
$jsonresults = json_decode($gresults);
if ($jsonresults->{'success'}===false ) {
// the code was incorrect
print "<font color=\"red\">Ошибка: введен неправильный проверочный код!</font><br /><br />";
}
else if ($jsonresults->{'success'}=== true )
{
echo "при отправке сообщения возникли ошибки";
}
}?>
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