In this example, the Codeigniter registration logon code is derived from a codeigniter project. Now, if you want to register a logon code for Codeigniter, refer to the following example ~
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