ThinkPHP automatic verification failure and solution_PHP tutorial

WBOY
Release: 2016-07-13 17:43:50
Original
765 people have browsed it

 /*

 * 登陆
 */
public function Login(){
if($_POST[submit]){
$DB = D(Login);//自定义Model处理
    //if里面就是ThinkPHP的自动验证了.
if(!$DB->create()){
$this->redirect(Index/Login, , 3, 错误信息: .$DB->getError().
系统将于3秒后返回重新登陆...);
}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, 错误信息: 用户名或密码错误
系统将于3秒后返回重新登陆...);
}
}
return ;
}
//这里只是将模板文件的地址封装了一下.
A(Public)->ShowPage(login);  
}
 
class LoginModel extends Model {
// 设置数据表
protected $tableName = admin;
// 自动验证设置
protected $_validate = array(
array(username,require,用户名必须!, 1),
array(userpwd,require,密码必须!, 1),
);
/* 自动填充 如果不能自动验证,将这段代码取消注释看看.
protected $_auto = array(
array(status,1,self::MODEL_INSERT),
array(create_time,time,self::MODEL_INSERT,function),
);*/
/*引用ThinkPHP2.0开发手册:ThinkPHP手册类型检查只是针对数据库级别的验证,所以系统还内置了数据对象的自动验证功能来完成模型的业务规则验证,而大多数情况下面,数据对象是由表单提交的$_POST数据创建。需要使用系统的自动验证功能,只需要在Model类里面定义$_validate属性
*/
/*它这里说了,只需要在Model类里面定义$_validate属性,但是在使用ThinkPHP2.1的时候,的的确确不能通过验证,$DB->getError()无错误原因返回,且刷新的时候$DB->getError()返回"令牌表单错误"
*/
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478811.htmlTechArticle/* * 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(Inde...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!