Home > Backend Development > PHP Tutorial > ThinkPHP automatic verification failure solution_PHP tutorial

ThinkPHP automatic verification failure solution_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:28:31
Original
709 people have browsed it

Copy code The code is as follows:

/*
* Login
*/
public function Login(){
if($_POST['submit']){
$DB = D('Login');//Custom Model processing
//If is the automatic verification of ThinkPHP.
if(!$DB->create()){
$this->redirect('Index/Login', '', 3, 'Error message: '.$DB->getError().'
The system will return to log in again after 3 seconds...');
}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: Wrong username or password
The system will return and log in again after 3 seconds...');
}
}
return ;
}
//This is just the address of the template file Encapsulated.
A('Public')->ShowPage('login');
}

Copy code The code is as follows:

class LoginModel extends Model {
// Set data table
protected $tableName = 'admin';
/ / Automatic verification settings
protected $_validate = array(
array('username','require','Username is required!', 1),
array('userpwd','require',' The password is required! ', 1),
);
/* If automatic verification cannot be performed, uncomment this code and take a look.
protected $_auto = array(
array('status ','1',self::MODEL_INSERT),
array('create_time','time',self::MODEL_INSERT,'function'),
);*/
/*Quote ThinkPHP2. 0 Development Manual: ThinkPHP manual type checking is only for database-level verification, so the system also has built-in automatic verification function of data objects to complete the business rule verification of the model. In most cases, the data objects are $_POST data submitted by the form. create. If you need to use the system's automatic verification function, you only need to define the $_validate attribute in the Model class
*/
/* It is said here that you only need to define the $_validate attribute in the Model class, but when using ThinkPHP2.1 When, it indeed fails the verification, $DB->getError() returns without error reason, and when refreshing, $DB->getError() returns "Token Form Error"
*/
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323579.htmlTechArticleCopy code The code is as follows: /* * Login*/ public function Login(){ if($_POST['submit ']){ $DB = D('Login');//Custom Model processing//if contains ThinkPHP's automatic verification. if(!$DB...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template