Captcha不工作在CI [英] Captcha not working in CI

查看:258
本文介绍了Captcha不工作在CI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一小段代码,应该在Codeigniter中使用验证码。代码应该只打印验证码创建的时间,第一次尝试。但它似乎甚至不创建验证码本身。我相信帮助器加载,这是在构造函数中完成。接下来,将图像写入文件夹的正确权限应该在那里。任何人都知道为什么它不能正常工作?

I wrote a small piece of code which should work for a captcha in Codeigniter. The code should just simply print the time the captcha was created, for a first try. But it doesn't seem to even create the captcha itself. I'm sure the helper is loaded, this is done in the construct function. Next to that, the correct rights for writing the image to a folder should be there. Anyone any idea why it isn't working as it should?

defined('BASEPATH') OR exit('No direct script access allowed');
class Register extends CI_Controller{

     public function __construct(){
        parent::__construct();  
        $this->load->helper('captcha');
    }

    public function generate_captcha(){
        $vals = array(
            'img_path' => './captcha/',
            'img_url' => base_url().'captcha/',
        );
        echo base_url().'assets/images/captcha/';
        $captcha = create_captcha($vals);

        echo 'cap time: ' . $captcha['time'];

        $captcha_image = $captcha['image'];
        return $captcha_image; 
    }

}

>
它可以与除了这个代码之外的东西有关吗?我已经为文件夹设置了正确的权限,因此可以将图片写入目录。

Edit Could it have anything to do with something apart from this code? I already set the correct rights to the folder, so it can write images to the directory.

推荐答案

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Mycaptcha extends CI_Controller  {

public function __construct() {

    parent::__construct();  
        $this->load->helper('captcha');
        $this->load->helper('url');
    }

    public function index() { 
        $vals = array(
            'img_path' => './captcha/',
            'img_url' => base_url().'/captcha/',
        );

        $captcha = create_captcha($vals);
        $captcha_image = $captcha['image'];

        print_r($captcha);
    }
}

请确保您有:


  1. 使用权限在root上创建文件夹captcha 777

  2. 在config.php $ config ['base_url '] ='http:// localhost / yourproject /';

  1. Create folder captcha on root with permission 777
  2. In config.php $config['base_url'] = 'http://localhost/yourproject/';

这篇关于Captcha不工作在CI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆