【发布时间】:2016-07-07 05:47:21
【问题描述】:
所以,看起来很简单,我在我的website 中添加了一个 Google 验证码,并在 HTML 代码中添加了以下内容。
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="g-recaptcha" data-sitekey="My key would be here"></div>
但是,人们仍然可以在不完成验证码的情况下填写表格并发送邮件。 (所以他们不必解决任何他们可以直接解决的难题,这当然让我容易受到机器人的攻击)
所以,我基本上需要 PHP 代码来检查用户是否真的“勾选”或“完成”了 Recaptcha。这样他们就可以继续发送邮件了。
我的 PHP 代码:
if ($_POST['submit']) {
if ($email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>You have successfully submitted your information to PS4RS. Subscribers to our mailing list will begin to periodically receive updates.</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>';
}
}
?>
我真的不知道如何用 PHP 编码,这是我最好的尝试。
【问题讨论】:
-
你还没有实现任何东西within the server-side validation from the documentation。先试试看。
-
@brimstone 不。那只是他现有表单的 PHP,与那里的 Google Recaptcha 无关。
-
如果您Google it,您会发现需要如何在代码中实施 Google reCAPTCHA 的示例。