Public Function Index () {
if (is_post) {
$admin =d (' admin ');
if ($admin->create ($_post,4)) {
// Dump ($admin->create ($_post,4)); die;
if ($admin->login ()) {
$this->success (' login succeeded ', U (' Index/index '));
} else{
$this->error (' username or password is wrong. ');
}
} else{
$this->error ($admin->geterror ());
}
return;
}
$this->display ();
}
This is the login controller inside the method, used to receive the login interface from the account and password, $admin->create ($_post,4) Why use 4 it, because in the administrator of the controller inside, there are model models, have to add data, edit data, There are all the conditions attached, and the login This is the fourth kind of gas mine to prevent automatic verification, the focus is login () This method of writing, go to admin this module inside
Public Function Login () {
$password = $this->password;
Dump ($this->username);
Die;
$data [' username ']= $this->username;
$info = $this->where ($data)->find ();
Dump ($info);
Die;
if ($info) {
if ($info [' Password ']==md5 ($password)) {session
(' ID ', $info [' id ']);
Session (' username ', $info [' username ']);
return true;
} else{return
false;
}
else{return
false;
}
$this->password on behalf of the reception received the password, $this->username representative to accept the front desk account, and then recorded in the data array and then query ¥admin username= $this-> Username this line of data,
If the ¥info this data is not NULL to indicate that there is this account, otherwise there is no return false, if Moma is equal to the password after encryption, name the account exists in the session array
It's a pretty cheap egg. Clear the value on the session.
Public Function Layout () {session
(NULL);
$this->redirect (' Login/index ');
}