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"
*/
}
?>
http://www.bkjia.com/PHPjc/323579.htmlwww.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...