Skip to content Skip to sidebar Skip to footer

Tutorial on Creating an Online Store Using Codeigniter: Register and Login Member [Bagian 2]

Register or Sign Up used to register (become member) by registering through registration by filling in biodata. Whereas login or Sign in is the process of logging into a service on line which usually contains username and password.

These two things are like a perfect match in the service system on line, specifically website. In the case of creating a shop website on lineof course, with the presence of these two processes, it is very necessary when a person customer must register as a member at the store to be able to proceed to the next stage, namely delivery and payment of goods.

Also Read:

According to the author’s promise, that is to continue making the store website on line to the next stage of making register and login.

REGISTER AND LOGIN

1. Make table users in the database shop.

CREATE TABLE `users` (  `id` int(10) NOT NULL,  `username` varchar(25) NOT NULL,  `email` varchar(50) NOT NULL,  `password` varchar(60) NOT NULL,  `group` tinyint(1) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;ALTER TABLE `users`ADD PRIMARY KEY (`id`);

Program Logic:

  • Table users this is useful for storing member and admin data in website shop on line. The structure of this table consists of fields en (primary key), username, email, password and group.

The following is a structural view of table users.

2. Create files Regis.php in the folder C:\xampp\htdocs\online-shop\application\controllers.

load->model('model_regis');		}		public function index(){			$username=$this->input->post('username');			$email=$this->input->post('email');			$password=$this->input->post('password');			$group=$this->input->post('group');			$this->model_regis->tambah($username,$email,$password,$group);			redirect('regis/member');		}		public function member(){			$this->load->view('form_regis');		}		public function tambah(){			$this->load->view('form_login');		}	}?>

Program Logic:

  • public function index serves to define field from table users so that you can enter wheninput into that table. Besides that, it is also useful for summoning model_regis by the name function plus to add a new member from the store website on line.
  • public function member serves to display files form_login.php found in folder views.
  • public function add works when user has finished filling in the personal data in the menu registerthen they can return to the menu login to enter member dashboard and continue the shopping process on line.

3. Make files Model_regis.php in the folder C:\xampp\htdocs\online-shop\application\models.

 $username,				'email' => $email,				'password' => $password,				'group' => $group,				);			$this->db->insert('users',$data);		}	} ?>

Program Logic:

  • public function index add function to create data array to store the value when user toinput personal bio like username, email, password and group. After that add the data that is input into the table users.

4. Make files form_regis.php in the folder C:\xampp\htdocs\online-shop\application\views.

			Toko Online | Inwepo												load->view('layout/top_menu') ?>		
session->flashdata('error')?>
'form-horizontal'])?>

Now, to see the appearance of this register menu, readers can type in the URL http://localhost/toko-online/index.php/regis. Here’s a view of register:

5. Make files Login.php in the folder C:\xampp\htdocs\online-shop\application\controllers.

form_validation->set_rules('username','Username','required|alpha_numeric');		$this->form_validation->set_rules('password','Password','required|alpha_numeric');				if($this->form_validation->run() == FALSE)		{			$this->load->view('form_login');		} else {			$this->load->model('model_users');			$valid_user = $this->model_users->check_credential();						if($valid_user == FALSE)			{				$this->session->set_flashdata('error','Wrong Username / Password!');				redirect('login');			} else {				// if the username and password is a match				$this->session->set_userdata('username', $valid_user->username);				$this->session->set_userdata('group', $valid_user->group);								switch($valid_user->group){					case 1 : //admin								redirect('admin/products'); 								break;					case 2 : //member								redirect(base_url());								break;					default: break; 				}			}		}	}	public function logout()	{		$this->session->sess_destroy();		redirect('login');	}}

Program Logic:

  • public function index function to make form validation in process login. As well as displaying files login.php contained in folder view. In the function This is useful for giving login rules by entering username and password to enter member dashboard. The presence of this program snippet can also regulate session who entered to determine member or admin with field groups. You do this by using conditions like this: If group is 1 then it is declared admin, whereas if group is 2 then it is stated member.
  • public function logout function to exit member dashboard or admin and will return to the main page.

6. Make files model_users in the folder C:\xampp\htdocs\online-shop\application\models.

db->where('username', $username)						  ->where('password', $password)						  ->limit(1)						  ->get('users');				if($hasil->num_rows() > 0){			return $hasil->row();		} else {			return array();		}	}}

Program Logic:

  • public function check_credential serves to check the login process by matching the username and password data. If the data is valid then the process login successful and can enter the next menu.

7. Make files form_login.php in the folder C:\xampp\htdocs\online-shop\application\views.

			Toko Online | Inwepo												load->view('layout/top_menu') ?>				
session->flashdata('error')?>
'form-horizontal'])?>

After forming files above, the reader can do the trial stage by typing the URL http://localhost/toko-online/index.php/login. Here is how the form looks login the.

In the process login also the system has been able to determine user who enter by knowing the data in the field groups. If record is 1, then it is declared as admin, while if it is 2 it is declared as members.

This means indirectly, the author has provided material multi-level for this login process. The next stage is the manufacturing process dashboard members. So when the system knows if the group is worth 2, then the system will immediately direct to member dashboard for order goods.

Therefore, continue to follow the process of making this online store website, loyal friend of Inwepo. ️

DOWNLOAD

Table users.sql

Regis.php (Controllers)

Login.php (Controllers)

Model_regis.php (Models)

Model_users.php (Models)

Form_Regis.php (Views)

Form_Login.php (Views)