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 ();}}}