Using SESSION in ThinkPHP to implement user login verification

Source: Internet
Author: User

Using SESSION in ThinkPHP to implement user login verification

A user can log on to a home page in either of the following two States: a visitor's identity logon, or a server-verified identity logon.

For these two types of logon, we will mainly talk about:

When we use thinkphp, first of all, it does not improve the login authentication function, but is relatively secure in terms of the path, because if we do not perform sufficient authentication for the login identity, users can try to log on to your backend management, which is terrible. Therefore, you must first understand a very important business logic.

If you log on by entering the user name and password normally, you should write the session data before the jump, and then log on with the data. However, if you do not enter the password, then it will inevitably have no session data, so we can determine whether the session data exists or not, but this judgment should also be prior to the jump.

Therefore, it is very important to store and read session data. It must be used flexibly:

The following is the logon instance code. due to security reasons, it is not all released. It is for reference only.

Class ManagerController extends Controller {public function login () {// This is the login verification module if (empty ($ _ POST) | ($ _ POST ['username'] = 'enter username') {$ this-> display ();} else {$ info = D ('userinfo'); $ res = $ info-> select (); $ username = $ _ POST ['username']; $ password = md5 ($ _ POST ['Password']); $ ver = 0; foreach ($ res as $ key => $ value) {if ($ res [$ key] ['username'] = $ username & $ res [$ key] ['Password'] = $ password) {$ ver ++ ;}}if ($ ver) {S ('username', $ username); $ this-> assign ('username ', S ('username'); $ this-> display ('index/Index'); // $ this-> success ("Logon successful ", U ('index/Index');} else {// echo "Incorrect username or password"; $ this-> assign ("error_info ", "Your username or password is incorrect"); $ this-> display ();}}}


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.