2016-12-24 17 views
0

我有一个自定义网站,没有CMS,而且这个网站使用Smarty。该网站允许用户注册并使用旧的图像验证码系统。 要禁止机器人注册,我将实施新的Google No Captcha Recaptcha插件,(更多信息请点击:https://www.google.com/recaptcha/)。在Smarty中使用php no captcha recaptcha代码

所以我决定遵循本教程:https://webdesign.tutsplus.com/tutorials/how-to-integrate-no-captcha-recaptcha-in-your-website--cms-23024

我在第一个步骤没有任何问题:注册在谷歌和网站获取密钥和秘密密钥。

在以下步骤中也没问题:在register.tpl smarty模板文件中插入JavaScript API和div框。

我的问题是在最后的步骤中,发送到谷歌的回复,以便它可以验证它。 这是正常的网站把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页面,但我是一个初学者,你能否为我转换这段代码? 我确信这段代码对于网络上的许多用户会很有用。

回答