好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

ThinkPHP验证码和分页 - Thinkphp

ThinkPHP验证码和分页

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Image 类库是否正确导入;

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

CommonAction.class.php

<?php  class  CommonAction  extends  Action{       function  verify(){                 import( 'ORG.Util.Image' );           //英文验证码            //Image::buildImageVerify(5,5,gif,90,30,'verify');            //中文验证码           Image::GBVerify();      }          }  ?> 

模板index.html

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

控制器UserAction.class.php

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

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

UserAction.class.php

function  index(){      import( 'ORG.Util.Page' ); //引入分布类        $user =M( 'user' );       $count = $user -> count ();       $page = new  Page( $count ,3); //一页显示5条        $page ->setConfig( 'theme' , '<div style="font-weight:bold;">总共:%totalRow%%header%&nbsp;%nowPage%/%totalPage%页&nbsp;%first%&nbsp;%upPage%&nbsp;%prePage%&nbsp;%linkPage%&nbsp;%nextPage%&nbsp;%downPage%&nbsp;%end%</div>' );       $show = $page ->show();       $list = $user ->field( array ( 'id' , 'username' , 'createip' ))->order( 'id desc' )->limit( $page ->firstRow. ',' . $page ->listRows)->select();       $this ->assign( 'alist' , $list );       $this ->assign( 'page' , $show );       $this ->display();  } 

模板页index.html

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

查看更多关于ThinkPHP验证码和分页 - Thinkphp的详细内容...

  阅读:75次