//console
function code(){
$this->load->model('Myzm');
echo $this->Myzm->yzm();
}
//model
function yzm() {
//设置验证码参数
$vals = array(
'img_path' => './captcha/', //验证码图片保存路径
'img_url' => 'http://localhost/myday/captcha/', //验证码显示路径
// 'img_width' => '100', //验证码图片宽度
'img_height' => '25',
'num' => '4',
'expiration' => 3 //验证码保存时长,超时自动销毁
);
$cap = create_captcha($vals);
$data = array('captcha_time' => $cap['time'],
'ip_address' => $this -> input -> ip_address(),
'word' => $cap['word']
);
// 输出页面
return isset($cap['image'])?$cap['image']:'Agin,Please refresh. ';//显示验证码
}
//view 一部分
/**
*
* 验证码
*
*/
echo form_label('验证码:','yzm');
$ndata = array(
'type'=>'text',
'name'=>'yzm',
'size'=>'10'
);
echo form_input($ndata);
//echo $yzm;
?>
<img src="<?php echo site_url('user/code');?>" alt="点击刷新" class="codes" id="codeg"/>
<?php
echo '<br>';
/**
*
* 结束表单数据
*
*/
echo form_submit('submit','注册');
echo form_close();
//js
function codess()
{
var el =document.getElementById("codeg");
el.src="<?php echo site_url('user/code');?>/" + Math.random();
}