thinkphp Realization Login function

Source: Internet
Author: User

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 functionChecknamepwd ($name,$pwd)    {                //① based on $name query whether there is a record of the specified name//find the entire record by $name        $res=$this->where ("Mg_name="$name' ")find (); if($res) {                        //② Compare the password of the queried record with the password entered by the user            if($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 '];//Verify that the entire record is returned successfully, otherwise null is returned$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 back Home $this->redirect (' Index/index '); }Else{    Echo"User name or password error";}

thinkphp Realization Login function

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.