This article mainly and everybody introduced in detail the thinkphp realizes the login to exit the function, has the certain reference value, the interest small partner may consult, hoped can help to everybody.
<?php/** * User Login and Exit * After successful registration, the page will be redirected to the login login page * When the data is submitted to the landing page, the verification code must be executed before the login operation */public function Checkyzm ($yzm) {$verif Y=new \think\verify ();//Instantiate the Verify method with TP if ($verify->check ($YZM)) {//Call the Check method return true;} else{echo ' Verification code error '; Exit (); }}public function Login () {if (!is_post) {$this->display ();} else{//If verification code is verified via if ($this->checkyzm (' Post.yzm ')) {$username =i (' post.username '); $user =d (' user ')->where ("Username= ' $username '")->find (); Post the password splicing salt MD5 after the password = database password, then through if (MD5 (I (' Post.password '). $user [' salt ']) = = = $user [' Password ']{cookies (' username ', $userp [' username ']);//write Cookie $this->redirect ('/');//Jump to Home}else{echo ' username or password is incorrect '; }}}}/**V Layer * Exit Login * Read cookie $Think. cookie *///without cookie data Hello Welcome to <if condition= "$Think. Cookie.username eq Null" >< A href= "{: U (' Home/user/login ')}" rel= "external nofollow" rel= "external nofollow" style= "color: #50884b" > Login </a > |<a href= "{: U (' Home/user/reg ')}" rel= "ExternaL nofollow "style=" color: #50884b "> Free registration </a> |<else/>{$Think. Cookie.username}|<<a href=" {: U (' Home/user/login ')} "rel=" external nofollow "rel=" external nofollow "style=" color: #50884b "> Exit </a> </if >/** * Exit method * 1,cookie set to NULL, delete cookie * 2. Jump to Homepage */Public Function logout () {cookie (' username ', null); $this->redirect ('/'); };