tp5 implements login and saves the session, and then jumps to the page with different role permissions

little bottle
Release: 2023-04-06 08:26:02
forward
5209 people have browsed it

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; } }
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!