码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-12-09 17:48:04      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:thinkphp框架拓展包使用方式详细介

拓展压缩包的使用方式详细介绍


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

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

标签:thinkphp框架拓展包使用方式详细介

原文地址:http://blog.csdn.net/leyangjun/article/details/41825835

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!