thinkphp code sharing to implement login Exit function

Source: Internet
Author: User
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" >&lt 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 ('/'); };

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.