本文实例讲述了CI框架验证码CAPTCHA 辅助函数的用法,分享给大家供大家参考。具体如下:
使用CAPTCHA 辅助函数很方便生成验证码,但是图片是存储在文件夹下,不是输出流,感觉不够完美,可以拿来用用。
说明:产生4位的随机数,CI根目录下建立captcha文件夹。
<?php <br />$this->load->helper('captcha');<br />$vals = array(<br /> 'word' => rand(<p style="color:transparent">2本文来源gao!daima.com搞$代!码网</p><span>搞代gaodaima码</span>1000, 10000),<br /> 'img_path' => './captcha/',<br /> 'img_url' => 'http://localhost/ci/captcha/',<br /> //'font_path' => './path/to/fonts/texb.ttf',<br /> 'img_width' => '150',<br /> 'img_height' => 30,<br /> 'expiration' => 7200<br /> );<br />$cap = create_captcha($vals);<br />echo $cap['image'];<br />?>
运行结果如下图所示:
希望本文所述对大家的CI框架程序设计有所帮助。