原文:
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('該用戶不存在'); } } }