ThinkPHP實(shí)現(xiàn)登錄退出功能
更新時(shí)間:2017年06月29日 17:06:31 作者:SYsunyi
這篇文章主要為大家詳細(xì)介紹了ThinkPHP實(shí)現(xiàn)登錄退出功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了ThinkPHP實(shí)現(xiàn)登錄退出功能的具體代碼,供大家參考,具體內(nèi)容如下
<?php /** * 用戶登陸與退出 * 注冊(cè)成功后,將頁面跳轉(zhuǎn)到login登陸頁面 * 當(dāng)數(shù)據(jù)提交到登陸頁面后,必須先執(zhí)行驗(yàn)證碼驗(yàn)證通過再執(zhí)行登陸操作 */ public function checkyzm($yzm){ $verify=new \Think\Verify();//實(shí)例化TP自帶的Verify方法 if($verify->check($yzm)){//調(diào)用check方法 return true; }else{ echo '驗(yàn)證碼錯(cuò)誤'; exit(); } } public function login(){ if(!IS_POST){ $this->display(); }else{ //若驗(yàn)證碼驗(yàn)證通過 if($this->checkyzm(I('post.yzm'))){ $username=I('post.username'); $user=D( ' user ' )->where(" username='$username' ")->find(); //post過來的password拼接鹽md5后密碼=數(shù)據(jù)庫的密碼,則通過 if(md5( I( ' post.password ' ) . $user[ ' salt ' ])===$user['password']{ cookie('username' , $userp[ ' username ' ]);//寫入cookie $this->redirect('/');//跳轉(zhuǎn)到首頁 }else{ echo '用戶名或密碼不對(duì)'; } } } } /**V層 * 退出登陸 * 讀取cookie $Think.cookie */ //若沒有cookie數(shù)據(jù) 您好歡迎觀臨 <if condition="$Think.cookie.username eq null"> <a href="{:U('Home/User/login')}" rel="external nofollow" rel="external nofollow" style="color:#50884b">登陸</a> | <a href="{:U('Home/User/reg')}" rel="external nofollow" style="color:#50884b">免費(fèi)注冊(cè)</a> | <else /> {$Think.cookie.username}| <<a href="{:U('Home/User/login')}" rel="external nofollow" rel="external nofollow" style="color:#50884b">退出</a> </if> /** * 退出方法 * 1,cookie設(shè)為null,刪除cookie * 2. 跳轉(zhuǎn)到首頁 */ public function logout(){ cookie('username' , null); $this->redirect('/'); } ?>}
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
PHP實(shí)現(xiàn)繪制二叉樹圖形顯示功能詳解【包括二叉搜索樹、平衡樹及紅黑樹】
這篇文章主要介紹了PHP實(shí)現(xiàn)繪制二叉樹圖形顯示功能,結(jié)合實(shí)例形式分析了php繪制常見二叉樹的相關(guān)操作技巧,包括二叉搜索樹、平衡樹及紅黑樹的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-11-11PHP基于MySQL數(shù)據(jù)庫實(shí)現(xiàn)對(duì)象持久層的方法
這篇文章主要介紹了PHP基于MySQL數(shù)據(jù)庫實(shí)現(xiàn)對(duì)象持久層的方法,實(shí)例分析了php實(shí)現(xiàn)持久層的相關(guān)技巧,需要的朋友可以參考下2015-06-06php簡單解析mysqli查詢結(jié)果的方法(2種方法)
這篇文章主要介紹了php簡單解析mysqli查詢結(jié)果的方法,結(jié)合實(shí)例形式簡單列舉了查詢結(jié)果存入對(duì)象與數(shù)組的兩種實(shí)現(xiàn)方法,需要的朋友可以參考下2016-06-06php 過濾英文標(biāo)點(diǎn)符號(hào)及過濾中文標(biāo)點(diǎn)符號(hào)代碼
這篇文章主要介紹了php過濾英文標(biāo)點(diǎn)符號(hào)及過濾中文標(biāo)點(diǎn)符號(hào)的方法,需要的朋友可以參考下2014-06-06