PHP头条
热点:

ThinkPHP验证码和分页


验证码:导入验证码类,在aoli\ThinkPHP\Lib\ORG\Util\Image.class.php里有验证码方法    

英文验证码:buildImageVerify($length,$mode,$type,$width,$height,$verifyName)

length:验证码的长度,默认为 4 位数

mode:验证字符串的类型,默认为数字,其他支持类型有 0 字母 1 数字 2 大写字母 3 小写字母 4

中文 5 混合(去掉了容易混淆的字符 oOLl 和数字 01 )

type:验证码的图片类型,默认为 png

width:验证码的宽度,默认会自动根据验证码长度自动计算

height:验证码的高度,默认为 22

verifyName:验证码的 SESSION 记录名称,默认为 verify

中文验证码:GBVerify ($length,$type,$width,$height,$fontface,$verifyName)

length:验证码的长度,默认为 4 位数

type:验证码的图片类型,默认为 png

width:验证码的宽度,默认会自动根据验证码长度自动计算

height:验证码的高度,默认为 50

fontface:使用的字体文件,使用完整文件名或者放到图像类所在的目录下面,默认使用的字体文件是 simhei.ttf(该文件可以从 window 的 Fonts 目录下面找到)

verifyName:验证码的 SESSION 记录名称,默认为 verify

如果无法显示验证码,请检查:

PHP 是否已经安装 GD 库支持;

输出之前是否有任何的输出(尤其是 UTF8 的 BOM 头信息输出);

Image 类库是否正确导入;

如果是中文验证码检查是否有拷贝字体文件到类库所在目录;

CommonAction.class.php

  1. class CommonAction extends Action{ 
  2.     function verify(){        
  3.         import('ORG.Util.Image'); 
  4.         //英文验证码 
  5.         //Image::buildImageVerify(5,5,gif,90,30,'verify'); 
  6.         //中文验证码 
  7.         Image::GBVerify(); 
  8.     }    
  9.     
  10. ?> 

模板index.html

  1.  验证码:<input type="text" name="verify" /><img src="__APP__/common/verify" onclick="show(this)" /><br /> 
  2.   <input type="submit" value="注册" /> 
  3. form> 
  4. <script type="text/javascript"> 
  5.     function show(obj){ 
  6.         obj.src="__APP__/common/verify/random/"+Math.random();        
  7.     } 
  8. script> 

控制器UserAction.class.php

  1. //验证码验证 
  2. if($_SESSION['verify']!=md5($_POST['verify'])){ 
  3.     $this->error('验证码不正确');      

分页://导入分页类,在aoli\ThinkPHP\Lib\ORG\Util\Page.class.php里有验证码方法.

UserAction.class.php

  1. function index(){ 
  2.     import('ORG.Util.Page');//引入分布类 
  3.     $user=M('user'); 
  4.     $count=$user->count(); 
  5.     $page=new Page($count,3);//一页显示5条 
  6.     $page->setConfig('theme','总共:%totalRow%%header% %nowPage%/%totalPage%页 %first% %upPage% %prePage% %linkPage% %nextPage% %downPage% %end%'); 
  7.     $show=$page->show(); 
  8.     $list=$user->field(array('id','username','createip'))->order('id desc')->limit($page->firstRow.','.$page->listRows)->select(); 
  9.     $this->assign('alist',$list); 
  10.     $this->assign('page',$show); 
  11.     $this->display(); 

模板页index.html

  1. <volist name="alist" id="vo"> 
  2.   <li><span>ID:span>{$vo['id']}<span>用户名:span>{$vo['username']}<span>注册ip:span>{$vo['createip']}<a href="__URL__/del/id/{$vo['id']}">删除a>  <a href="__URL__/edit/id/{$vo['id']}">编辑a>li> 
  3. volist> 
  4. {$page} 

www.phpzy.comtrue/phpkj/7106.htmlTechArticleThinkPHP验证码和分页 验证码:导入验证码类,在aoli\ThinkPHP\Lib\ORG\Util\Image.class.php里有验证码方法 英文验证码:buildImageVerify($length,$mode,$type,$width,$height,$verifyName) length:验证码的长度,默认为...

相关文章

相关频道:

PHP之友评论

今天推荐