【问题标题】:Using php no captcha recaptcha code in Smarty在 Smarty 中使用 php no captcha recaptcha 代码
【发布时间】: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


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 2015-03-02
      • 2015-11-18
      • 2015-12-28
      • 2011-11-18
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2011-04-02
      • 2015-09-16
      相关资源
      最近更新 更多