我写了一小段代码,它应该适用于Codeigniter中的验证码.代码应该只是简单地打印验证码创建的时间,首先尝试.但它似乎甚至没有创建验证码本身.我确定帮助器被加载,这是在构造函数中完成的.除此之外,将图像写入文件夹的正确权限应该在那里.任何人都知道为什么它不工作,因为它应该?
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; } }
<?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); } }
确保你有:
>在根目录下创建文件夹captcha,权限为777>在config.PHP $config [‘base_url’] =’http:// localhost / yourproject /’;