thinkphp simple implementation of the function of login with account

Source: Internet
Author: User
This article is mainly for you to introduce the thinkphp to achieve a simple landing function, with a certain reference value, interested in small partners can refer to

Idea: The front desk input account password, backstage custom a function checknamepwd () to verify the account password is correct or not, in the controller call, wherein, CHECKNAMEPWD () method verifies the account password correctness is first through the account to find the password, Then the search out the password and user input password comparison, the same login success, otherwise login failed!

First, define a function checknamepwd () in the model class.

Public Function Checknamepwd ($name, $pwd)  {        //① First queries whether there is a record of the specified name based on $name    //To find the entire record through $name    $res = $this- >where ("Mg_name= ' $name '")->find ();    if ($res) {            //② compares the password of the queried record to the password entered by the user      ($res [' mg_pwd ']=== $pwd) {        return $res;      }    } else{      return null;    }  }

The controller receives information entered by the user and calls the Checknamepwd () method

$manager = new \model\managermodel (); $name = $_post[' Admin_user '); $pwd = $_post[' admin_psd '];//validation successfully returns the entire record, otherwise returns null$ info = $manager->checknamepwd ($name, $pwd);    if ($info) {      //Verify success, give user information session persistence operation (NAME,ID) session (' admin_id ', $info [' mg_id ']); session (' Admin_name ', $info [ ' Mg_name ']);      Jump Backstage Home $this->redirect (' Index/index '); }else{  echo "User name or password error";}

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

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.