您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
CI中的验证码
发布时间:2020-01-29 13:24:00编辑:雪饮阅读()
基础使用
控制器
$this->load->helper('url');
$this->load->helper('captcha');
$vals=[
'img_path'=>'./captcha/',//用于存储验证码图片的目录,需要手动建立
'img_url'=>base_url().'/captcha/',
'img_width'=>'100',
'img_height'=>30,
'expiration'=>60*10//过期秒数,时间一到会自动删除图片
];
$cap=create_captcha($vals);
$this->load->view('index2.html',["cap"=>$cap["image"]]);
视图
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<?=$cap?>
</body>
</html>
取出生成的验证码字符
$this->load->helper('url');
$this->load->helper('captcha');
$vals=[
'img_path'=>'./captcha/',
'img_url'=>base_url().'/captcha/',
'img_width'=>'100',
'img_height'=>30,
'expiration'=>60*10
];
$cap=create_captcha($vals);
echo $cap["word"];
exit();
自定义生成的验证码字符
$this->load->helper('url');
$this->load->helper('captcha');
$vals=[
'word'=>rand(1000,9999),
'img_path'=>'./captcha/',
'img_url'=>base_url().'/captcha/',
'img_width'=>'100',
'img_height'=>30,
'expiration'=>60*10
];
$cap=create_captcha($vals);
echo $cap["word"];
exit();
关键字词:ci,验证码
上一篇:CI中的Session
下一篇:CI中的表单验证