使用CAPTCHA 辅助函数很方便生成验证码,但是图片是存储在文件夹下,不是输出流,感觉不够完美,可以拿来用用。
说明:产生4位的随机数,CI根目录下建立captcha文件夹。
$this->load->helper('captcha'); $vals = array( 'word' => rand(1000, 10000), 'img_path' => './captcha/', 'img_url' => 'http://localhost/ci/captcha/', //'font_path' => './path/to/fonts/texb.ttf', 'img_width' => '150', 'img_height' => 30, 'expiration' => 7200 );
$cap = create_captcha($vals); echo $cap['image'];
?>
参考:http://codeigniter.org.cn/user_guide/helpers/captcha_helper.html