FleaPHP如何使用验证码?
poLo
验证码比较单一
能否有多种验证码样式可供选择?
关于参数:
附加选项,可以指定字体、宽度和高度等参数
不知道是该怎么写 ARRAY?
复制内容到剪贴板
代码:
ex: $imgcode->image(1, 5, 1000, array('字体', '长', '宽'));PS:我是指样式, 并非字母数字等......(这个不是代码的问题,比较私人的想法
dualface
请查看
API 文档的 Helper 包中的 FLEA_Helper_ImgCode。
引用:
FLEA_Helper_ImgCode 类实现了一个简单的图像验证码生成器,并带有检查验证方法
当启用了 session 时,验证码会保存在 session 中。用法:
模版页面中,在需要显示验证码的地方使用 - <img src="<?php echo $this->_url('imgcode'); ?>" />
接下来为显示验证码的控制器编写 imgcode 方法: - function actionImgcode() {
- $imgcode =& get_singleton('FLEA_Helper_ImgCode');
- $imgcode->image();
- }
最后,对于用户提交的表单做如下验证: - function actionSubmit() {
- $imgcode =& get_singleton('FLEA_Helper_ImgCode');
- // 假定验证码在表单中的字段名是 imgcode
- if ($imgcode->check($_POST['imgcode'])) {
- // 验证通过
- }
- }
复制内容到剪贴板
代码:
利用 GD 库产生验证码图像
目前 $options 参数支持下列选项:
* paddingLeft, paddingRight, paddingTop, paddingBottom
* border, borderColor
* font, color, bgcolor
如果 font 为 0-5,则使用 GD 库内置的字体。 如果要指定字体文件,则 font 选项必须为字体文件的绝对路径,例如:
1.
$options = array('font' => '/var/www/example/myfont.gdf');
2.
image($type, $length, $lefttime, $options);
void image (int $type, [int $length = 4], [ $lefttime = 900], [array $options = null])
* int $type: 验证码包含的字符类型,0 - 数字、1 - 字母、其他值 - 数字和字母
* int $length: 验证码长度
* int $leftime: 验证码有效时间(秒)
* array $options: 附加选项,可以指定字体、宽度和高度等参数 PS: phpDocumentor 貌似有点 bug,生成的文档中,FLEA_Com_ImgCode::image() 方法最后多出来了一个 int $lefttime 参数。奇怪。。。。。
poLo
array('font' => '/var/www/example/myfont.gdf');
噢 明白了 是这样得格式
我先以为就是 array('/var/www/example/myfont.gdf');