2016-03-04 81 views
0

我從我的註冊控制器調用驗證碼模型。 「insert_captcha()模型函數加載驗證碼助手,更新驗證碼錶,並將創建的驗證碼返回給顯示在視圖中的寄存器控制器驗證碼創建時Codeigniter驗證碼助手錯誤

它工作正常50%的時間,但我不時讓PHP錯誤的大名單:

提取模型:

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'   => 'abcdefghijklmnopqrstuvwxyz', 
     '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; } 
} 
} 

提取控制器的

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);  
    } 
} 

的錯誤

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 

回答