THINKPHP5 log in and save session, jump different pages according to different user rights

Source: Internet
Author: User
Tags md5
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; }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.