简体   繁体   English

如何将phpcaptcha添加到OpenCart

[英]How to add phpcaptcha to OpenCart

Could someone please tell me how I can add the Phpcaptcha (secureimage) library to OpenCart? 有人可以告诉我如何将Phpcaptcha(secureimage)库添加到OpenCart吗?

So far I can show the image in the template file catalog\\view\\theme\\default\\template\\information\\contact.tpl: 到目前为止,我可以在模板文件目录\\视图\\主题\\默认\\模板\\信息\\ contact.tpl中显示图像:

<img id="captcha" src="system/library/securimage/securimage_show.php" alt="CAPTCHA Image" />
<a href="#" onclick="document.getElementById('captcha').src = 'system/library/securimage/securimage_show.php?' + Math.random(); return false">
<img src="system/library/securimage/images/refresh.png" height="25" width="25" alt="Reload Image" onclick="this.blur()" align="bottom" border="0"></a>
<input type="text" id="captcha_code" name="captcha" size="31" maxlength="6" value="" onblur="check('captcha_code');" />

but I don't know what to do with the controller. 但我不知道该如何处理控制器。 Where and how do I load the Secureimage library and initialise the Secureimage class and set its variables and validate the image? 我在哪里以及如何加载Secureimage库并初始化Secureimage类并设置其变量并验证图像?

Will very much appreciate your help. 非常感谢您的帮助。 Thank you. 谢谢。

[SOLVED] [解决了]

I got it. 我知道了。 In the catalog\\controller\\information\\contact.php comment out and include this code in the validate(): 在catalog \\ controller \\ information \\ contact.php中,注释掉并将以下代码包含在validate()中:

//if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
    //$this->error['captcha'] = $this->language->get('error_captcha');
//}

$this->load->library('securimage/securimage');
$captcha = new Securimage();
$captcha_code = (isset($_POST['captcha_code'])) ? $_POST['captcha_code'] : '';
$valid = $captcha->check($captcha_code);
if (!$valid) {
    $this->error['captcha'] = $this->language->get('error_captcha');
}

PS. PS。 Assuming the secureimage library is located in /system/library/secureimage 假设secureimage库位于/ system / library / secureimage中


[ALTERNATIVE SOLUTION - DOESN't WORK YET] [替代解决方案-尚无法使用]

I've added the securimage to the index.php: 我已将securimage添加到index.php:

require_once(DIR_SYSTEM . 'library/securimage/securimage.php');
$registry->set('securimage', new Securimage($registry));

changed contact.tpl: 更改了contact.tpl:

<img id="captcha" src="index.php?route=information/contact/securimage" alt="CAPTCHA Image" />
<a href="#" onclick="document.getElementById('captcha').src = 'system/library/securimage/securimage_show.php?' + Math.random(); return false">
<img src="system/library/securimage/images/refresh.png" height="25" width="25" alt="Reload Image" onclick="this.blur()" align="bottom" border="0"></a>

the controller has: 控制器具有:

if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha_code'])) {
    $this->error['captcha'] = $this->language->get('error_captcha');
}

public function securimage() {
$securimage = new Securimage();
$this->session->data['captcha'] = $securimage->getCode();
$securimage->show();
}   

I've got the picture, but after POST, it gives me an error - it seems the code doesn't get verified. 我有图片,但是在POST之后,它给了我一个错误-似乎代码没有得到验证。

  1. Add the library file to system/library/ folder. 将库文件添加到system/library/文件夹。
  2. Include the library file in index.php file like: (for reference check how the customer.php library file is added and used.) 将库文件包含在index.php文件中,例如:(作为参考,请检查如何添加和使用customer.php库文件。)

    require_once(DIR_SYSTEM . 'library/secureimage.php'); require_once(DIR_SYSTEM。'library / secureimage.php');

    // Secure captcha //add after $registry->set('customer', new Customer($registry)); //安全验证码//在$ registry-> set('customer',new Customer($ registry))之后添加; $registry->set('securecaptcha', new Securecaptcha($registry)); $ registry-> set('securecaptcha',new Securecaptcha($ registry));

  3. Add a new function for your new captcha image in catalog/controller/information/contact.php and generate the image. catalog/controller/information/contact.php为新的验证码图像添加新功能,并生成图像。 (refer the default captcha function) (请参阅默认的验证captcha功能)

  4. In catalog/view/theme/default/template/information/contact.tpl (replace default with your theme folder name if you're not using the default theme), replace <img src="index.php?route=information/contact/captcha" alt="" /> with your new function like <img src="index.php?route=information/contact/securecaptchaimage" alt="" /> catalog/view/theme/default/template/information/contact.tpl (更换default ,如果你不使用默认的主题与你的主题文件夹的名称),替换<img src="index.php?route=information/contact/captcha" alt="" />和新功能,例如<img src="index.php?route=information/contact/securecaptchaimage" alt="" />

Have a nice day !! 祝你今天愉快 !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM