【发布时间】:2016-12-24 10:03:10
【问题描述】:
我有一个自定义网站,没有 CMS,而且这个网站使用 Smarty。该网站允许用户注册并使用旧的图像验证系统。 为了禁止机器人注册,我将实施新的 Google No Captcha Recaptcha 插件,(更多信息在这里:https://www.google.com/recaptcha/)。
所以我决定学习这个教程:https://webdesign.tutsplus.com/tutorials/how-to-integrate-no-captcha-recaptcha-in-your-website--cms-23024
我在第一步没有问题:在谷歌上注册并获得站点密钥和密钥。
以下步骤也没有问题:在 register.tpl smarty 模板文件中插入 JavaScript API 和 div 框。
我的问题出现在最后的步骤中,请发送给 Google 回复,以便它进行验证。 这在普通网站中将 php 代码放在 register.php 普通 php 页面中是没有问题的。 但是在 Smarty 模板上,所以在 register.tpl 中,它给了我致命的错误,如果我使用 {php}{/php} 特殊标签
<?php
// grab recaptcha library
require_once "recaptchalib.php";
// your secret key
$secret = "0000000000000000000000000000000000";
// empty response
$response = null;
// check our secret key
$reCaptcha = new ReCaptcha($secret);
// if submitted check response
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["g-recaptcha-response"]
);
}
?>
还有这个:
<?php
if ($response != null && $response->success) {
echo "Hi " . $_POST["name"] . " (" . $_POST["email"] . "), thanks for submitting the form!";
} else {
?>
<?php } ?>
我认为解决方案是将这段代码放在 register.php 页面中,然后将其导入 register.tpl 页面,但我是初学者,你能帮我转换一下这段代码吗? 我相信这段代码会对网络上的许多用户有用。
【问题讨论】:
标签: javascript php smarty recaptcha