首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建captcha时Codeigniter captcha助手错误

创建captcha时Codeigniter captcha助手错误
EN

Stack Overflow用户
提问于 2016-03-04 12:57:10
回答 1查看 1.1K关注 0票数 0

我从我的寄存器控制器调用一个captcha模型。"insert_captcha() model函数加载captcha助手,更新captcha表,并将创建的captcha返回到Register控制器,该控制器将其显示在视图中。

它可以正常工作50%的时间,但我不时地会收到一大串php错误列表:

模型的摘录:

代码语言:javascript
复制
class captcha_model extends CI_Model {


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

public function insert_captcha() {

    //captcha creation
    $vals = array(
        'img_path'      => './captcha/',
        'img_url'       =>   base_url() . 'captcha',
        'font_path'     => './assets/fonts/OpenSans-Bold.ttf',
        'img_width'     => '150',
        'img_height'    => 30,
        'expiration'    => 900,
        'word_length'   => 8,
        'font_size'     => 16,
        'img_id'        => 'captcha-pic',
        'pool'          => '0123456789abcdefghijklmnopqrstuvwxyz',
        'colors'        => array(
            'background' => array(255, 255, 255),
            'border' => array(255, 255, 255),
            'text' => array(0, 0, 0),
            'grid' => array(255, 40, 40)
        )
    );
    $captcha = create_captcha($vals);

    //insert captcha into DB
    $captcha_db_params = array(
        'captcha_time'  => $captcha['time'],
        'ip_address'    => $this->input->ip_address(),
        'word'          => $captcha['word']
    );

    $query = $this->db->insert_string('captcha', $captcha_db_params);
    if ( $this->db->query($query) ) { return $captcha;  }           
    else { return false; } 
}
}

控制器的提取

代码语言:javascript
复制
class Register extends CI_Controller {

public $data = array();

public function __construct() {

        parent::__construct();
        $this->load->model('captcha_model');

        if ($this->session->userdata('logged_in')) {  
            $this->data['name'] = $this->session->userdata('name');
            $this->data['id'] = $this->session->userdata('id');
            $this->data['email'] = $this->session->userdata('email');
            $this->data['isAdmin'] = $this->session->userdata('isAdmin');
        }
        if (!empty($this->session->flashdata('error'))) { $this->data['error'] = $this->session->flashdata('error'); }

}

public function index() {

    //captcha creation success
    if ($cap = $this->captcha_model->insert_captcha()) {

        $this->data['title'] = 'Register';
        $this->data['captcha'] = $cap;
        $this->template->load('default', 'register/register', $this->data);

    }

    //not supposed to happen
    else {
        $this->data['error'] = 'Erreur systeme, captcha non genere';
        $this->template->load('default', 'register/register', $this->data);     
    }
}

错误

代码语言:javascript
复制
A PHP Error was encountered

Severity: Notice

Message: **Uninitialized string offset: 36**

Filename: helpers/captcha_helper.php

Line Number: 174

Backtrace:

File: C:\wamp\www\jpweb\models\captcha_model.php Line: 48 Function: create_captcha

File: C:\wamp\www\jpweb\controllers\Register.php Line: 26 Function: insert_captcha

File: C:\wamp\www\index.php Line: 292 Function: require_once A PHP Error was encountered

Severity: Warning

Message: **unpack(): Type C: not enough input, need 1, have 0**

Filename: helpers/captcha_helper.php

Line Number: 174

Backtrace:

File: C:\wamp\www\jpweb\models\captcha_model.php Line: 48 Function: create_captcha

File: C:\wamp\www\jpweb\controllers\Register.php Line: 26 Function: insert_captcha

File: C:\wamp\www\index.php Line: 292 Function: require_once A PHP Error was encountered

Severity: Notice

Message: **String offset cast occurred**

Filename: helpers/captcha_helper.php

Line Number: 206

Backtrace:

File: C:\wamp\www\jpweb\models\captcha_model.php Line: 48 Function: create_captcha

File: C:\wamp\www\jpweb\controllers\Register.php Line: 26 Function: insert_captcha

File: C:\wamp\www\index.php Line: 292 Function: require_once A PHP Error was encountered

Severity: Notice

Message: **Uninitialized string offset: 37**

Filename: helpers/captcha_helper.php

Line Number: 174

Backtrace:

File: C:\wamp\www\jpweb\models\captcha_model.php Line: 48 Function: create_captcha

File: C:\wamp\www\jpweb\controllers\Register.php Line: 26 Function: insert_captcha

File: C:\wamp\www\index.php Line: 292 Function: require_once A PHP Error was encountered

Severity: Warning

Message: **unpack(): Type C: not enough input, need 1, have 0**

Filename: helpers/captcha_helper.php

Line Number: 174

Backtrace:

File: C:\wamp\www\jpweb\models\captcha_model.php Line: 48 Function: create_captcha

File: C:\wamp\www\jpweb\controllers\Register.php Line: 26 Function: insert_captcha

File: C:\wamp\www\index.php Line: 292 Function: require_once A PHP Error was encountered

Severity: Notice

Message: **String offset cast occurred**

Filename: helpers/captcha_helper.php

Line Number: 206

Backtrace:

File: C:\wamp\www\jpweb\models\captcha_model.php Line: 48 Function: create_captcha

File: C:\wamp\www\jpweb\controllers\Register.php Line: 26 Function: insert_captcha

File: C:\wamp\www\index.php Line: 292 Function: require_once
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-04 13:28:25

这是一个CodeIgniter bug:https://github.com/bcit-ci/CodeIgniter/issues/4427

即将发布的3.0.5版本将修复它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35796680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档