A method of user login verification using session in thinkphp
The user boarded a home page there are two states, one is similar to the identity of the visitor login, the other is the identity of the past has been logged on as a server authenticated login.
For both of these logins, the main words are:
When we use thinkphp, first of all, he does not improve the login verification function, is only in the path to do relatively safe, because if we do not have sufficient authentication login identity, the user can completely try to login to your background management, then this is very scary, so, The first thing to understand is a very important business logic.
If you follow the normal input user name password to log in, before jumping we should write session data, and then log in with the data, but if the user does not enter a password to log in, then it must not have session data, we judge the existence of the session data, But this judgment should be before the jump.
Therefore, the session data deposit and reading is very important, it must be flexible to use the line:
The following is the login instance code, due to security factors, and not all released, for reference only
Class Managercontroller extends Controller {public function login () { //////This is the login verification module if (empty ($_post) | | ($_post[' username ']== ' Please enter your 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 ("Login Successful", U (' Index/index '));} else{//echo "Incorrect user name or password
"; $this->assign (" Error_info "," Your user name or password is wrong "); $this->display ();}}