Click here to Skip to main content
15,896,557 members
Articles / Programming Languages / PHP

Captcha Plug-in in CodeIgniter

Rate me:
Please Sign up or sign in to vote.
4.92/5 (12 votes)
29 Jul 2008CPOL2 min read 96.4K   2.3K   8  
How to use thr captcha plugin in CodeIgniter.
<?php
 class Captcha_model extends Model
 {
 	private $vals = array();
 	
	private $baseUrl  = 'http://localhost/captchademo/';
	private $basePath = 'D:/apache2triad/htdocs/captchademo/';
	
	private $captchaImagePath = 'tmp/captcha/';
	private $captchaImageUrl  = 'tmp/captcha/';
	private $captchaFontPath  = 'c:/windows/fonts/verdana.ttf';
	
	public function __construct($configVal = array())
	{
		parent::Model();
		
		$this->load->plugin('captcha');		
		
		if(!empty($config))
			$this->initialize($configVal);
		else
			$this->vals = array(
								'word'		 	=> '',
								'word_length'	=> 6,
								'img_path'	 	=> $this->basePath . $this->captchaImagePath,
								'img_url'	 	=> $this->baseUrl . $this->captchaImageUrl,
								'font_path'	 	=> $this->captchaFontPath,
								'img_width'	 	=> '150',
								'img_height' 	=> 50,
								'expiration' 	=> 3600
							   );	
	}	
	
	/**
	 * initializes the variables
	 *
	 * @author 	Mohammad Jahedur Rahman <jahed01@gmail.com>
	 * @access 	public
	 * @param 	array 	config
	 */		 	
	public function initialize ($configVal = array())
	{
		$this->vals = $configVal;
	} //end function initialize
	
	//---------------------------------------------------------------
	
	/**
	 * generate the captcha
	 *
	 * @author 	Mohammad Jahedur Rahman <jahed01@gmail.com>
	 * @access 	public
	 * @return 	array
	 */	
	public function generateCaptcha () 
	{
		$cap = create_captcha($this->vals);
		
		return $cap;	
	} //end function generateCaptcha	
 }
?>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Bangladesh Bangladesh
Software Engineer, Bangladesh.

Comments and Discussions