本文主要和大家詳細介紹了ThinkPHP實現登錄退出功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能幫助到大家。
<?php public function checkyzm($yzm){ $verify=new \Think\Verify();//實例化TP自帶的Verify方法 if($verify->check($yzm)){//調用check方法 return true; }else{ echo '驗證碼錯誤'; exit(); } } public function login(){ if(!IS_POST){ $this->display(); }else{ //若驗證碼驗證通過 if($this->checkyzm(I('post.yzm'))){ $username=I('post.username'); $user=D( ' user ' )->where(" username='$username' ")->find(); //post過來的password拼接鹽md5后密碼=數據庫的密碼,則通過 if(md5( I( ' post.password ' ) . $user[ ' salt ' ])===$user['password']{ cookie('username' , $userp[ ' username ' ]);//寫入cookie $this->redirect('/');//跳轉到首頁 }else{ echo '用戶名或密碼不對'; } } } } //若沒有cookie數據 您好歡迎觀臨 <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">免費注冊</a> | <else /> {$Think.cookie.username}| <<a href="{:U('Home/User/login')}" rel="external nofollow" rel="external nofollow" style="color:#50884b">退出</a> </if> public function logout(){ cookie('username' , null); $this->redirect('/'); } ?>}
相關推薦:
Yii2框架自動登錄以及登錄退出功能的實現方法
以上就是ThinkPHP實現登錄退出功能的代碼分享的詳細內容,更多請關注php中文網其它相關文章!