ThinkPhp学习13
生活随笔
收集整理的這篇文章主要介紹了
ThinkPhp学习13
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
原文:ThinkPhp學(xué)習(xí)13
簡單登錄驗(yàn)證
創(chuàng)建Login類
1 <?php 2 class LoginAction extends Action { 3 function index(){ 4 $this->display(); 5 } 6 function do_login(){ 7 //獲取用戶名和密碼等。和數(shù)據(jù)庫中比對,有該用戶允許登錄否則輸出錯誤頁面 8 $username=$_POST['username']; 9 $password=$_POST['password']; 10 $code=$_POST['code']; 11 12 if($_SESSION['verify']!==md5($code)){ //$_SESSION['verify']tp默認(rèn)創(chuàng)建的session不需要修改成code 13 $this->error('驗(yàn)證碼錯誤!'); 14 } 15 16 $m=M('User'); 17 $where['username']=$username; 18 $where['password']=$password; 19 $i=$m->where($where)->count(); 20 if($i>0){ 21 $this->redirect('User/index'); 22 }else{ 23 $this->error('該用戶不存在'); 24 } 25 } 26 } 27 ?>Login類對應(yīng)的模板
1 <div style="width:400px;margin:0 auto"> 2 <form action="__URL__/do_Login" method="post"> 3 用戶名:<input type="text" name="username" /><br/> 4 密 碼:<input type="password" name="pwd" /><br/> 5 驗(yàn)證碼:<input type='text' name='code'/><img src="__APP__/Code/code" οnclick="this.src=this.src+'?'+Math.random()"/><br/> //src=Code類下的code方法,Math.random() 避免緩存無法刷新 6 <input type="submit" value="登錄"/> 7 </form> 8 </div>創(chuàng)建驗(yàn)證碼類
1 <?php 2 class CodeAction extends Action{ 3 function code(){ 4 import('ORG.Util.Image'); 5 Image::buildImageVerify(); 6 } 7 } 8 9 ?>?
總結(jié)
以上是生活随笔為你收集整理的ThinkPhp学习13的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android消息机制——时钟显示和异步
- 下一篇: shell基础二:查找技巧,find及x