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!