您的位置:首页 > 编程语言 > PHP开发

Thinkphp框架拓展包使用方式详细介绍--验证码实例(十一)

2014-12-09 16:58 274 查看
拓展压缩包的使用方式详细介绍



1:将拓展包解压:ThinkPHP3.1.2_Extend.zip --> 将其下的 \Extend 文件全部复制



2:将复制的文件放入项目中 E:\wamp\www\thinkphp\ThinkPHP\Extend(安装的时候这里面是空文件),你自己的项目目录

即可



=============================以下是,拓展包中验证码的使用========================================

比如用到拓展包的验证码:(看手册-->杂项)

在:E:\wamp\www\thinkphp\Home\Lib\Action\ 新建:PublicAction.class.php 代码如下 --必须加

//直接使用code里面的代码即可生成验证码

class PublicAction extends Action{ //按照手册说明走就行

function
code(){

import('ORG.Util.Image');

Image::buildImageVerify();

}

}

//目录/thinkphp/index.php/Public/code点击变换验证码onclick

前台模板页面调用验证码:

<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('该用户不存在');

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: