In this example, the Codeigniter registration logon code is derived from a codeigniter project. For more information, see the CI framework.
In this example, the Codeigniter registration logon code comes from a codeigniter project ~
Because the Active Record class is used, generally there are only two layers of database operations, namely C and V.
Controllers/login. php file:
The code is as follows: Class Login extends CI_Controller {
Private $ pass = '';
Public function _ construct (){
Parent: :__ construct ();
$ This-> load-> helper (array (
'Form ',
'URL'
));
$ This-> load-> library ('session ');
}
Public function index (){
$ This-> load-> view ('login ');
}
Public function formsubmit (){
$ This-> load-> library ('form _ validation ');
$ This-> form_validation-> set_rules ('username', 'username', 'required ');
$ This-> form_validation-> set_rules ('password', 'password', 'required ');
If ($ this-> form_validation-> run () = FALSE ){
$ This-> load-> view ('login ');
} Else {
If (isset ($ _ POST ['submit ']) &! Empty ($ _ POST ['submit ']) {
$ Data = array (
'User' => $ _ POST ['username'],
'Pass' => md5 ($ _ POST ['password'])
);
$ Newdata = array (
'Username' => $ data ['user'],
'Userip' => $ _ SERVER ['remote _ ADDR '],
'Luptime' => time ()
);
If ($ _ POST ['submit '] = 'login '){
$ Query = $ this-> db-> get_where ('UC _ user', array (
'User' => $ data ['user']
), 1, 0 );
Foreach ($ query-> result () as $ row ){
$ Pass = $ row-> pass;
}
If ($ pass = $ data ['pass']) {
$ This-> session-> set_userdata ($ newdata );
$ This-> load-> view ('usercenter', $ data );
}
} Else if ($ _ POST ['submit '] = 'register '){
$ This-> session-> set_userdata ($ newdata );
$ This-> db-> insert ('UC _ user', $ data );
$ This-> load-> view ('usercenter', $ data );
} Else {
$ This-> session-> sess_destroy ();
$ This-> load-> view ('login ');
}
}
}
}
}
Views/login. php file:
The code is as follows:
SQL statement:
Uc_user: The code is as follows: create table 'UC _ user '(
'Id' int (11) unsigned zerofill not null AUTO_INCREMENT,
'User' varchar (20) not null,
'Pass' char (32) not null,
'Role' enum ('root', 'normal') not null default 'root ',
'Del 'decimal (1, 0) not null default '0 ',
Primary key ('id ')
) ENGINE = InnoDB AUTO_INCREMENT = 5 default charset = latin1