Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在CodeIgniter中获取验证码图像_Php_Codeigniter_Captcha - Fatal编程技术网

Php 无法在CodeIgniter中获取验证码图像

Php 无法在CodeIgniter中获取验证码图像,php,codeigniter,captcha,Php,Codeigniter,Captcha,我正在尝试创建一个登录页面。我想使用CI的助手添加验证码图像,但未能成功 Login.php class Login extends CI_Controller { public function __construct() { parent::__construct(); } public function index() { $this->load->helper(array('form', 'url', 'captc

我正在尝试创建一个登录页面。我想使用CI的助手添加验证码图像,但未能成功

Login.php

class Login extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {

        $this->load->helper(array('form', 'url', 'captcha'));

        $captchaSettings = array(
            'img_path' => base_url() . 'captcha',
            'img_url' => base_url() . 'captcha',
            'font_path' => base_url() . 'system/fonts/captcha4.ttf',
            'img_width' => '300',
            'img_height' => '40',
            'expiration' => '3600',
            'word_length' => 6,
            'font_size' => 16,
            'img_id' => 'captchaImage',
            'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
            // White background and border, black text and red grid
            'colors' => array(
                'background' => array(255, 255, 255),
                'border' => array(255, 255, 255),
                'text' => array(0, 0, 0),
                'grid' => array(255, 40, 40)
            )
        );

        $dataCaptcha = create_captcha($captchaSettings);
        $this->load->view('login_form', array('captcha' => $dataCaptcha));

    }
}
当我使用
var\u dump
查看它包含的内容时,login\u form.php获取captcha图像,但显示
boolean false

<?php var_dump($captcha); //boolean false?>


它看起来像是
create\u captcha()
返回
false
而不是图像。所以我无法得到图像。但是我按照教程所说的做了。

根据函数的CodeIgniter API,这些可能是导致布尔值为false的原因

 61:         if ($img_path == '' OR $img_url == '')
 62:         {
 63:             return FALSE;
 64:         }
 65: 
 66:         if ( ! @is_dir($img_path))
 67:         {
 68:             return FALSE;
 69:         }
 70: 
 71:         if ( ! is_writable($img_path))
 72:         {
 73:             return FALSE;
 74:         }
 75: 
 76:         if ( ! extension_loaded('gd'))
 77:         {
 78:             return FALSE;
 79:         }
因此请确保:

  • 您发送img_路径和img_url参数(请注意我的评论) 关于参数名称中可能的输入错误)

  • img_路径是一个现有的目录,也是可写的

  • 您已经安装了GD扩展

  • 路径/URL

    我相信这是因为您使用的是
    base\u url()验证码“
    作为您的
    img\u路径

    base\u url()
    返回格式为:
    http://www.domain.com/
    虽然路径应该是另一种格式(相对),例如:
    /directory/captache/
    根据函数的CodeIgniter API,这些可能是获取布尔值false的原因

     61:         if ($img_path == '' OR $img_url == '')
     62:         {
     63:             return FALSE;
     64:         }
     65: 
     66:         if ( ! @is_dir($img_path))
     67:         {
     68:             return FALSE;
     69:         }
     70: 
     71:         if ( ! is_writable($img_path))
     72:         {
     73:             return FALSE;
     74:         }
     75: 
     76:         if ( ! extension_loaded('gd'))
     77:         {
     78:             return FALSE;
     79:         }
    
    因此请确保:

  • 您发送img_路径和img_url参数(请注意我的评论) 关于参数名称中可能的输入错误)

  • img_路径是一个现有的目录,也是可写的

  • 您已经安装了GD扩展

  • 路径/URL

    我相信这是因为您使用的是
    base\u url()验证码“
    作为您的
    img\u路径

    base\u url()
    返回格式为:
    http://www.domain.com/
    而路径应该是另一种格式(相对),类似于:
    /directory/captache/

    使用captcha帮助程序
    要求。是的,应该是。更改后,它仍然返回布尔false。考虑在<代码> BaseIurl()之后添加<代码> /<代码>。验证码“。顺便问一下,为什么
    path
    url
    使用相同的值?URL应该包括
    www..
    ,而路径类似于:
    /directory/..
    使用验证码助手的要求。是的,应该是。更改后,它仍然返回布尔false。考虑在<代码> BaseIurl()之后添加<代码> /<代码>。验证码“
    。顺便问一下,为什么
    path
    url
    使用相同的值?URL应该包括
    www..
    而路径类似于:
    /directory/..
    它对我有效我更改了我的代码如下
    **'img_path'=>'img/captcha/,'img_URL'=>base_URL()。'img/captcha/'**
    它对我有效我更改了代码如下
    **'img_path'=>'img/captcha/,'img_URL'=>base_URL().“img/captcha/”**