Nie jestem programistą, uczę się sam krok po korku.W związku z atakiem botów na mój formularz kontaktowy, chce się zabezpieczyć za pomocą reCaptcha v2 od Google. Udało mi się osadzić ją w formularzu ale nie wiem w którym miejscu i jak ją obsłużyć w takim skrypcie (w komentarzu coś co udało mi się w poradniku przeczytać ale nie wiem jak to użyć w tym przypadku, gdzie sprawdzać $result):
<?php
$ciag='!QAZ2wsx@#$-P';
$odp1 = $_POST['miasto'];
if (empty($_POST['submit'])) { <table border=\"0\" class=\"menu\"><form method=\"post\">
<tr>
<td>Message</td>
<td><textarea name=\"tresc\" style=\"width: 350px; height: 140px; padding:10px 10px;border: 1px double #d4d4d4; color:#000000;box-shadow: 0px 1px 5px #acacac;\"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td><input type=\"text\" name=\"imie\" style=\"width: 350px; padding:10px 10px;border: 1px double #d4d4d4; color:#000000;box-shadow: 0px 1px 5px #acacac;\"></td>
</tr>
<td>Phone</td>
<td><input type=\"text\" name=\"telefon\" style=\"width: 350px; padding:10px 10px;border: 1px double #d4d4d4; color:#000000;box-shadow: 0px 1px 5px #acacac;\"></td>
</tr>
<tr>
<td>E-mail</td>
<td><input type=\"menu\" name=\"email\" style=\"width: 350px; padding:10px 10px;border: 1px double #d4d4d4; color:#000000;box-shadow: 0px 1px 5px #acacac;\"></td>
</tr>
<tr>
<td></td>
<td><input type=\"text\" name=\"nazwisko\" style=\"display:none;\"></td>
<td><input type=\"text\" name=\"miasto\" style=\"display:none;\" value=$ciag></td>
</tr>
<td> </td>
<td><div class=\"g-recaptcha\" data-size=\"compact\" data-sitekey=\"xxxxxxxxxxxxxx\"></div></td>
<td><input type=\"submit\" name=\"submit\" class=\"buton\" value=\"Send e-mail\">
<input type=\"reset\" class=\"buton\" value=\"Clean form\"></td></form>
</tr>
</table>
"
;
/*
$secret = 'xxxxx';
$response = $_POST['g-recaptcha-response'];
$remoteip = $_SERVER['REMOTE_ADDR'];
$url = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$remoteip");
$result = json_decode($url, TRUE);
if ($result['success'] == 1) {
echo 'Nie jesteś botem';
}else{
echo
'Błędnie wypełnione pole reCAPTCHA';
}
} */
}elseif (!empty($_POST['tresc']) && !empty($_POST['imie']) && !empty($_POST['email']) && !empty($_POST['telefon']) && empty($_POST['nazwisko']) ) {
$email=$_POST['email'];
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) OR
$odp1 != $ciag) {
echo "<span class=\"menu\">Attention Error !! Introduced web address is incorrect !<br> Please enter the correct web address.<br><br> <a href=\"?cat=contact\" class=\"link\">Return to the form</font></span>"; /*echo $odp1; echo $ciag;*/ echo $responseKeys; } else
{
$message = "Message:\n$_POST[tresc]\n\nName: $_POST[imie] \nPhone: $_POST[telefon] \nE-mail: $_POST[email]";
$header = "From: $_POST[imie] <$_POST[email]>";
@mail("xxx@xxx.pl","Contact form website Asia Connecting Center","$message","$header") or
die('The message could not be delivered');
echo "<div align=\"center\" class=\"menu\"><strong>The message has been successfully delivered !</strong><br><br></div>"; echo "<a href=\"?id=contact\" class=\"link\">Return to the form</a></span>";
}
}
else echo "<span class=\"menu\">Attention Error !! Please fill in all blanks in a form ! <br><br><br> <a href=\"?cat=contact\" class=\"link\">Return to the form</font></span>";
?>