验证码创建时Codeigniter验证码助手错误
问题描述:
我从我的注册控制器调用验证码模型。 “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