This article describes how to complete the login and save session in Thinkphp5, and then jump to the corresponding page function based on different user rights. The following three steps are essential to complete this step.
First, the password check
Here the view layer submitted the user name and password is not encrypted, the data in the password is MD5 encrypted, so first encrypt the password, and then with the database records, if the consensus that success. Second, the session Save
If the validation succeeds, the user information is saved in the session. third, according to different permissions to jump
Sometimes we have different users to show the page is also different, then we need to jump to the user's permissions to the corresponding page. Iv. Implementation Code
//login Public Function login () {//password encryption and find records from the database $map [' username '] = input (' post.a ');
$map [' password '] = MD5 (input (' post.b '));
$user =db (' user ')->where ($where)->find ();
The session if ($user) {unset ($user ["PSD]") is saved if the validation succeeds;
Session ("User", $user [' id ']);
Jump if ($user [' quanxian '] = = 0) {$this->redirect (' Module1/index/index ') according to different permissions;
} elseif ($user [' quanxian '] = = 1) {$this->redirect (' Module2/index/index ');
else{$this->redirect (' Module3/index/index ');
}}else{print_r (' error! ');
return false; }
}