原文:
Thinkphp框架拓展包使用方式详细介绍--验证码实例(十一)
拓展压缩包的使用方式详细介绍php
1:将拓展包解压:ThinkPHP3.1.2_Extend.zip --> 将其下的 \Extend 文件所有复制
2:将复制的文件放入项目中 E:\wamp\www\thinkphp\ThinkPHP\Extend(安装的时候这里面是空文件),你本身的项目目录html
便可thinkphp
=============================如下是,拓展包中验证码的使用======================================== 数据库
好比用到拓展包的验证码:(看手册-->杂项)php框架
在:E:\wamp\www\thinkphp\Home\Lib\Action\ 新建:PublicAction.class.php 代码以下 --必须加框架
//直接使用code里面的代码便可生成验证码dom
class PublicAction extends Action{ //按照手册说明走就行post
function code(){
import('ORG.Util.Image');
Image::buildImageVerify();
}
}ui
//目录/thinkphp/index.php/Public/code点击变换验证码onclick
前台模板页面调用验证码:this
<img src="__APP__/Public/code" onclick='this.src=this.src+"?"+Math.random()'/> 便可生成验证码
所有html登陆页面
<form action='__URL__/do_login' method='post' name='myForm'>
用户名:<input type='text' name='username'/><br/>
密 码:<input type='password' name='password'/><br/>
验证码:<input type='text' name='code'/>
<img src="__APP__/Public/code" onclick='this.src=this.src+"?"+Math.random()'/>
</br/>
<img src='__PUBLIC__/Images/leyangjun.gif' onclick="sub()"/>
</form>
//登陆判断验证码 加:LoginAction.class.php(模块)
class LoginAction extends Action { function do_login(){ //获取用户名和密码等。和数据库中比对,有该用户容许登陆不然输出错误页面 $username=$_POST['username']; $password=$_POST['password']; $code=$_POST['code']; //输入框;<input type='text' name='code'/> if($_SESSION['verify']!==md5($code)){ $this->error('验证码错误!'); } $m=M('User'); $where['username']=$username; $where['password']=$password; $i=$m->where($where)->count(); if($i>0){ $this->redirect('User/index'); }else{ $this->error('该用户不存在'); } } }