PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

ThinkPHP学习笔记ThinkPHP的分页以及验证码的使用_PHP教程

原创
2016-07-14 10:08:20 718浏览

CommonAction

[php]
/**
* ThinkPHP中的
* 让其他的Action继承当前的CommonAction就可以了
*/
class CommonAction extends Action{
public function verify(){
//导入验证码类
//方式一:
import('ORG.Util.Image');
//方式二:@代表当前项目的lib文件夹(需要自己复制或者自己写一个新的类)
// import('@.ORG.Image')
// Image::buildImageVerify();
//扩展修改
/**
* @param string $length 位数
* @param string $mode 类型(0字母,1数字,2大写字母,3小写字母,4中文,5混合)
* @param string $type 图像格式
* @param string $width 宽度
* @param string $height 高度
* buildImageVerify($length=4,$mode=1,$type='png',$width=48,$height=22,$verifyName='verify')
*/
Image::buildImageVerify(5,5,'png',80,22);
//中文验证码(2.0会有一个问题:msubstr有错误)
//1.修改function::msubstr
//2.加入字体ttf需要放入image同级目录之下
//扩展可以去类文件中查看
// Image::GBVerify();
}
}
?>
PageAction
[php]
/**
* ThinkPHP中的
*/
class PageAction extends CommonAction{
public function index(){
//导入page
import('ORG.Util.Page');
$user=M('User');
$count=$user->count();
$page=new Page($count, 3);
//修改提示信息
$page->setConfig('header', "个会员");
$page->setConfig('prev', "上一组");
$page->setConfig('next', "下一组");
$page->setConfig('first', "首页");
$page->setConfig('last', "尾页");
//定义主题样式(去看文档)
// $page->setConfig('theme', '
%%
');
$show=$page->show();
$list=$user->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
$this->assign('title','page演示');
$this->assign('alist',$list);
$this->assign('page',$show);
$this->display();
}
function check(){
$verify=$_SESSION['verify'];
if ($verify!=md5($_POST['verify'])) {
$this->error("验证码错误");
}
}
function next(){
}
}
?>
index
[php]
验证码:
  • ID
    用户名
    IP
    function show(obj){
    obj.src="//m.sbmmt.com/m/faq/__APP__/common/verify?"+Math.random();
    }

    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477786.htmlTechArticleCommonAction [php] ?php /** * ThinkPHP中的 * 让其他的Action继承当前的CommonAction就可以了 */ class CommonAction extends Action{ public function verify(){ //导入验证...
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。