我有一个自定义网站,没有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
第一步我没有问题:在Google上注册并获取站点密钥和秘密密钥。
在以下步骤中也没有问题:在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页面,但是我是一个初学者,您能帮我转换一下这段代码吗?
我确信此代码对于网络上的许多用户都是有用的。
最佳答案
的PHP
require_once ('recaptchalib.php');
$mypublickey = "456723345";
$smarty->assign("captcha", recaptcha_get_html($mypublickey));
tpl
{$captcha}
http://devcodepro.com/view/22/8/reCaptcha-with-smarty
关于javascript - 在Smarty中使用PHP No Captcha Recaptcha代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41312265/