CodeIgniter Registering Login code sample _php Tutorial

Source: Internet
Author: User
Tags codeigniter
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:















User name
Password






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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.