****************************************************************
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class captcha extends HO_Admin {
public function __construct() {
parent::__construct(FALSE);
//image captcha library
$this->load->library('HO/HiimelCaptcha', array($this), 'captcha');
}
public function image() {
$this->xhr_protect();
header("Content-type: image/jpeg");
$arr = $this->captcha->createImage(6);
$im = reset(array_values($arr));
ob_start();
imagejpeg($im);
$this->output->cache(0);
$this->output->set_output('data:image/jpeg;base64,' . base64_encode(ob_get_clean()));
}
}
******************************************
if ($this->web_cache_minute > 0) {
$this->output->cache($this->web_cache_minute);
}
$this->output->set_output($this->web->page());
********************************************
<div class="captcha">
<div class="detail">
<div class="img">
<img src="" alt="" title="captcha">
</div>
<div class="inp">
<input type="text" maxlength="10" id="captcha_code" name="captcha_code">
<label>Дуурайж бичээрэй!</label>
</div>
</div>
</div>
<script>
(function reloadCaptchaImg(capimg) {
var link = '<?php echo admin_url('captcha/image?'); ?>' + getTimeAsLong();
$.ajax({
url: link,
success: function (result) {
var par = capimg.parent();
capimg.remove();
capimg = $('<img src="' + result + '"/>');
capimg.appendTo(par);
capimg.animate({'opacity': '1'}, {
duration: 300
});
}
});
})($('.captcha img'));
</script>