CodeIgniter使用Securimage驗證碼方式

1 https://www.phpcaptcha.org/ 下載後解壓縮到application\libraries\securimage
2 controller中新增function

[php]
function securimage() {
$this->load->library(‘securimage’);
$img = new Securimage();
$img->show();
}
[/php]

3 view裡面增加

[html]
<img id="captcha" src="<?=site_url(‘[controller classname]/securimage’)?>" alt=’captcha’ id=’captcha’ />
<a href="#" onclick=" document.getElementById(‘captcha’).src = document.getElementById(‘captcha’).src + ‘?’ + (new Date()).getMilliseconds()">重新產生驗證碼</a>
[/html]

4 驗證

[php]
$captchacode= $this->input->post(‘captchacode’);
$this->load->library(‘securimage’);
if ($this->securimage->check($captchacode)==true){
redirect(‘index’);
}
[/php]