会话类和URL 助手是自动加载的。
控制器:
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . 'captcha/',
'img_width' => '250',
'img_height' => '50');
$cap = create_captcha($vals);
$datacap = array('captcha_time' => $cap['time'], 'word' => $cap['word']);
$this->session->set_userdata($datacap);
$this->form_validation->set_rules('captcha_image', 'Captcha',
'required|callback_captchacheck');
if ($this->form_validation->run() == false)
{
$datatw['image'] = $cap['image'];
$datatw['file_view'] = "register";
$this->load->view('home', $datatw);
} else { // }
打回来:
public function captchacheck($capt)
{
$captss = $this->session->userdata('word');
if ($captss == $capt)
{
return true;
} else
{
$this->form_validation->set_message('captchacheck',
'Security number does not match.');
return false;
}
}
它返回安全号码不匹配。
echo $this->session->userdata('word');
查看和复制粘贴,但它不起作用。
错误已修复!
对不起,我搬家了:
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . 'captcha/',
'img_width' => '250',
'img_height' => '50');
$cap = create_captcha($vals);
$datacap = array('captcha_time' => $cap['time'], 'word' => $cap['word']);
$this->session->set_userdata($datacap);
至:
if ($this->form_validation->run() == false){
//
}
它运作良好:
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->helper('captcha');
$this->form_validation->set_rules('captcha_image', 'Captcha',
'required|callback_captchacheck');
if ($this->form_validation->run() == false)
{
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . 'captcha/',
'img_width' => '250',
'img_height' => '50');
$cap = create_captcha($vals);
$datacap = array('captcha_time' => $cap['time'], 'word' => $cap['word']);
$this->session->set_userdata($datacap);
$datatw['image'] = $cap['image'];
$datatw['file_view'] = "register";
$this->load->view('home', $datatw);
} else
{ }