ThinkPHP Automatic Verification failure Solution

Source: Internet
Author: User

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"
*/
}
?>

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.