This article mainly describes how to complete the login and save the session in tp5, and then jump to the corresponding page function according to different user permissions. Share it with everyone to learn together.
There are mainly the following steps to complete this step.
1. Password verification
The username and password submitted by the view layer here are not encrypted. The password in the data is md5 encrypted, so first The password is encrypted and then compared with the records in the database. If they are consistent, it is considered successful.
2. Session saving
If the verification is successful, the user information will be saved in the session.
3. Jump according to different permissions
Sometimes we display different pages for different users. In this case, we need to jump to according to the user's permissions. corresponding page.
4. Implementation code
// 登录 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'); } }else{ print_r ('error!'); return false; } }
Related tutorials: PHP video tutorial
php Chinese website Learning topic: php session (including pictures, texts, videos, cases)
The above is the detailed content of tp5 implements login and saves the session, and then jumps to the page with different role permissions. For more information, please follow other related articles on the PHP Chinese website!