This example CodeIgniter registered login code from a CodeIgniter project and now shares the following ~
Because the Active Record class is used, the general database operation is only two layers, that is, C and V
controllers/login.php file:
Copy CodeThe 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:
Copy the Code code as follows:
SQL statements:
Uc_user: Copy the Code code as follows: CREATE TABLE ' Uc_user ' (
' id ' int (one) unsigned zerofill not NULL auto_increment,
' User ' varchar (not NULL),
' Pass ' char (+) is 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
http://www.bkjia.com/PHPjc/788618.html www.bkjia.com true http://www.bkjia.com/PHPjc/788618.html techarticle This example CodeIgniter registered login code originated from a CodeIgniter project and is now shared ~ due to the use of the Active Record class, the general database operation is only two layers, that is, C and v Controlle ...