Copy codeThe Code is as follows:
/*
* Login
*/
Public function Login (){
If ($ _ POST ['submit ']) {
$ DB = D ('login'); // custom Model processing
// If is automatically verified by ThinkPHP.
If (! $ DB-> create ()){
$ This-> redirect ('index/login', '', 3, 'error message :'. $ DB-> getError (). '<br/> the system will return to re-login 3 seconds later... ');
} Else {
$ Con ['loginname'] =_ _ POST ['username'];
$ Con ['loginpwd'] = md5 ($ _ POST ['userpwd']);
$ List = $ DB-> where ($ con)-> find ();
If (count ($ list)> 0 ){
Echo 'OK ';
} Else {
$ This-> redirect ('index/login', '', 3, 'error message: incorrect user name or password <br/> the system will return a New Login in 3 seconds... ');
}
}
Return;
}
// Here, the address of the template file is encapsulated.
A ('public')-> ShowPage ('login ');
}
Copy codeThe Code is as follows:
<? Php
Class LoginModel extends Model {
// Set the data table
Protected $ tableName = 'admin ';
// Automatic Verification settings
Protected $ _ validate = array (
Array ('username', 'require ', 'user name is required! ', 1 ),
Array ('userpwd', 'require ', 'password required! ', 1 ),
);
/* Automatically fill in the code to see if it cannot be automatically verified.
Protected $ _ auto = array (
Array ('status', '1', self: MODEL_INSERT ),
Array ('create _ time', 'time', self: MODEL_INSERT, 'function '),
);*/
/* Reference ThinkPHP2.0 Development Manual: The ThinkPHP manual type check is only for database-level verification. Therefore, the system also has the built-in automatic verification function for data objects to complete model business rule verification, in most cases, the data object is created from the $ _ POST data submitted by the form. To use the automatic verification function of the system, you only need to define the $ _ validate attribute in the Model class.
*/
/* As mentioned here, you only need to define the $ _ validate attribute in the Model class. However, when using ThinkPHP2.1, it cannot pass verification. $ DB-> getError () no error cause is returned, and $ DB-> getError () returns "token form error" When refreshing"
*/
}
?>