CAPTCHA(captcha) Sample

<?php
/**
 * Captcha helper
 *
 * Created on 2011. 11. 18.
 * @author 불의회상 <hoksi2k@hanmail.net>
 * @package helper
 * @subpackage controllers
 * @version 1.0
 */
class Captcha_hlp extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		
		// Captcha Helper Load
		$this->load->helper('captcha');
		// Session Library Load
		$this->load->library('session');
	}
	
	function index() {
		$captcha_word = $this->input->post('captcha_word');
		
		if($captcha_word != '') {
			$data['result'] = $captcha_word == $this->session->flashdata('captcha_word') ? 'SUCESS' : 'FAIL';
		} else {
			$data['result'] = '';
		}
		$data['cap'] = $this->_auth_img();
		
		$this->load->view('captcha_hlp_sample', $data);
	}
	
	function _auth_img()
	{
		$captcha_word = rand(23678190, 96523469);
		$config = array(
		    'word'	 => $captcha_word,
		    'img_path'	 => FCPATH . 'sample/cap/',
		    'img_url'	 => site_url('sample/cap') . '/',
		    'font_path'	 => BASEPATH . 'fonts/texb.ttf',
		    'img_width'	 => '150',
		    'img_height' => 30,
		    'expiration' => 30
	    );
	    
	    $this->session->set_flashdata('captcha_word', $captcha_word);
	    
		return create_captcha($config);
	}	
}
<?php $this->load->view('inc/header')?>

<form method="post" action="<?=site_url('captcha_hlp')?>">
<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<thead>
<tr>
  <th width="30%">Captcha Image</th>
  <th></th>
</tr>
</thead>
<tr>
  <td><?=$cap['image']?></td>
  <td><input type="text" name="captcha_word" /></td>
</tr>
<tr>
  <td colspan="2" align="center"><input type="submit" value="  전            송   " /></td>
</tr>
</table>
</form>

<?php if($result != ''):?>
<hr />
전송 결과
<hr />
<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<tr>
  <td><?=$result;?></td>
</tr>
</table>
<?php endif;?>

<?php $this->load->view('inc/footer')?>

© Copyright by hoksi(Page rendered in 0.0218 seconds)