<a href="javascript:void(0);" onclick="load_captcha('captcha','<?php echo site_url('index/show_captcha')?>');" title="看不清,换一张" id="captcha" ><?php echo $image;?></a>
function load_captcha(id,url)
{
$("#"+id).html('');
$("#"+id).load(url);
}
$("#captcha").load('<?php echo site_url('index/show_captcha');?>');
Controller中方法
public function captcha()
{
$this->load->helper('captcha');
$vals = array(
'word' => rand(1000,9999),
'img_path' => './captcha/',
'img_url' => base_url().'captcha/',
'font_path' => './system/fonts/texb.ttf',
'img_width' => '90',
'img_height' => 35,
'expiration' => 7200
);
$this->session->set_userdata(array('word'=>$vals['word']));
$cap = create_captcha($vals);
return $cap['image'];
}
public function show_captcha()
{
echo $this->captcha();
}
captcha_helper.php
随即生成字符串后加入session记录
$CI =& get_instance();
$CI->session->set_userdata(array('word'=>$word));