本文主要講述如何在tp5中完成登錄并保存session、然后根據不同的用戶權限跳轉相應頁面功能的實現,分享給大家一起來學習一下。
完成該步驟主要有以下幾個步驟完成。
一、密碼校驗
這里view層提交過來的用戶名和密碼是不加密的,數據中的密碼是經過md5加密的,所以首先對密碼進行加密,然后跟數據庫中的記錄比對,如果一致則認為成功。
二、session保存
如果校驗成功則將用戶信息保存在session中。
三、根據不同權限跳轉
有時候我們對于不同的用戶展示的頁面也不同,這時就需要我們根據用戶的權限跳轉到相應的頁面。
四、實現代碼
- // 登錄
- public function login()
- {
- //密碼加密并從數據庫查找記錄
- $map['username'] = input('post.a');
- $map['password'] = md5(input('post.b'));
- $user=db('user')->where($where)->find();
- //驗證成功則保存session
- if ($user) {
- unset($user["psd"]);
- session("user", $user['id']);
- //根據不同權限跳轉
- if($user['quanxian'] == 0){
- $this->redirect('Module1/index/index');
- }
- elseif ($user['quanxian'] == 1) {
- $this->redirect('MOdule2/index/index');
- }
- else{
- $this->redirect('Module3/index/index');
- }
- //Vevb.com
- }else{
- print_r ('error!');
- return false;
- }
- }
|
新聞熱點
疑難解答
圖片精選