<?php
class Captcha_demo extends CI_Controller{
	public function index(){}
	
	public function test(){
		echo 'captcha_demo';
		   
		if(extension_loaded('gd')){
			echo '你可以使用gd<br>';
			foreach (gd_info() as $cate=>$value)
				echo "$cate: $value<br>";
		}else echo '没有安装gd扩展';
		
		$this->load->helper('url');
		$this->load->helper('captcha');
		$number = rand(1000,9999);//生成随机字符串
		$vals = array(
				'word'      => $number,//可指定验证码内容,如果是中文.需要有支持的字体
				'img_path'  => dirname(BASEPATH).'/captcha/',//生成的图片存放目录
				'img_url'   => base_url('/captcha/'),//图片链接地址
// 				'font_path' => './path/to/fonts/texb.ttf',//指定字体
				'img_width' => '150',
				'img_height'    => 30,
				'expiration'    => 5,//图片存放时间,如果过期,只有在被再次请求才会删除.单位秒
				'word_length'   => 8,
				'font_size' => 16,
				'img_id'    => 'Imageid',
				'pool'      => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
		
				// White background and border, black text and red grid
				'colors'    => array(
						'background' => array(255, 255, 255),
						'border' => array(255, 255, 255),
						'text' => array(0, 0, 0),
						'grid' => array(255, 40, 40)
				)
		);
		
		$cap = create_captcha($vals);
		echo $cap['word']."<br>";
		echo $cap['image'];
		
		$this->load->view('user/captcha_view_demo',array('cap'=>$cap['image']));
		
		// 原生session
		session_start();
		//存储验证码信息到PHP原生的session中.
		$_SESSION["cap"] = $cap['word'];
		
		//获取Session
		$word = $_SESSION['cap'];
		echo $word;
		
	}
}