Mar 8, 2017 - So This tutorial will provide you with a step by step guide that POPULAR TUTORIALS you can make your own C...
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
PHPCodify PHP
HOME
CodeIgniter
jQuery
Laravel
AngularJS
Write for Us
CODEIGNITER
CodeIgniter Login Registration System using MySQL Bootstrap
CodeIgniter Login Registration System using MySQL Bootstrap by Ehtesham Mehmood / February 22, 2017 / CodeIgniter, MySQL, PHP / 1 Comment
SEARCH HERE
Search the site
SUBSCRIBE TO NEWSLETTER
Email *
User login and registration system are necessary nowadays for any advanced dynamic web application, So today In this tutorial we will learn how to make CodeIgniter Login Registration System using MySQL Bootstrap.In
Subscribe
CodeIgniter, we can implement the login registration system script using the session library.So This tutorial will provide you with a step by step guide that
POPULAR TUTORIALS
you can make your own CodeIgniter login registration script by following below steps.
CodeIgniter CRUD using
Working:
Ajax,Bootstrap,Models
In this CodeIgniter Login Registration application, we have two HTML form
Remove Public from
made using Bootstrap Registration and Login.There is Database called CI-
Laravel URL - 2,519 views
Login-Registration containing users table.A user will register from the
Android Registration and
registration form and then login through the login form and can see his
Login System using
profile dashboard using sessions.If the user is not logged in he/she can not
PHP,MySQL and Retrofit
see his profile page because we made some checkpoints with the help of
Square API - 764 views
session.
Remove Index.php from
Project Screen Shots
and MySQL - 14,560 views
CodeIgniter URL - 639 views
Registration View http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
1/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
Add Remove Input Fields Dynamically using jQuery Bootstrap - 633 views
TAGS
.htaccess
AJAX
Android
Angular
angular2
angularjs
Bootstrap CodeIgniter
Login View
CRUD
Excel
Export
Form
FPDF
jQuery
JSON
Laravel
Login
MySQL
nodejs
PDF
PDO
PHP
Registration
Retrofit
URL
Validate
Validation
User Profile View Web Development
http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
2/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
Project Folder Structure
http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
3/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
Steps 1-Database and Tables for CodeIgniter Login Registration Script Go to your PHPMyAdmin and create a database named ci-login-registration. Copy the below SQL script and paste into your PHPMyAdmin SQL editor and run. --- Table structure for table `user` - CREATE TABLE `user` ( `user_id` int(11) NOT NULL, `user_name` varchar(50) NOT NULL, `user_email` varchar(50) NOT NULL, `user_password` varchar(50) NOT NULL, `user_age` int(11) NOT NULL, `user_mobile` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2-Insert Some Sample Data For the demo purpose, we have to enter some records into the database.you can copy below SQL queries and run into your SQL editor. --- Dumping data for table `user` - INSERT INTO `user` (`user_id`, `user_name`, `user_email`, `user_pass word`, `user_age`, `user_mobile`) VALUES (1, 'Ehtesham', '
[email protected]', '123', 23, 334443333), (2, 'Ehtesham', '
[email protected]', '123', 23, 2147483647), (3, 'farrukh', '
[email protected]', '123', 32, 232342343), (4, 'zaid', '
[email protected]', '202cb962ac59075b964b07152d234b70', 23, 324234234);
3-CodeIgniter Con gurations In this step, we will do some configuration in our codeigniter login registration project folder. Open your config file located in the application>config>config.php change your base url and remove index.php how you will do this step you can get this complete guide from here Remove Index.php from CI. Now open your autoload file located in the application>config>autoload.php and the http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
4/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
code $autoload['libraries'] = array(); replace it with this code $autoload['libraries'] = array('session','database'); . This will autoload the database and session library so we can use it in our application. Now open the database file located in the application>config>database.php and enter your hostname, user,password and database according to yours. 'hostname' => 'localhost', 'username' => 'root' , 'password' => ' ' , 'database' => 'ci-login-registration'. Now open your route file located in the application>config>routes.php. Here you can set your default controller which you want to run at the first when the application starts. I set the default controller User you can set like this $route['default_controller'] = 'user';
4-User Controller In this step, we will explain the Complete Controller of the Codeigniter login registration system. 4.1 -Open your , project folder and in the application>>controller folder create a file named User.php and paste the below code and save it.
So we created a class User and extends it through CI_Controller it’s a base controller. In the constructor, we are loading three libraries url, model and session. 4.2 – Index method for User Controller The index method will contain the code for loading the registration form view.So when the application starts registration form will appear on the first go.
http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
5/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
public function index() { $this->load->view("register.php"); }
4.3 – register_user() In this method we will get the user inputs from the codeigniter registration form and then check the email from the database that if this email already exist or not if exist it will show an error otherwise it will save the user data into the database using User model function register_user(), So user will be registered. public function register_user(){ $user=array( 'user_name'=>$this->input->post('user_name'), 'user_email'=>$this->input->post('user_email'), 'user_password'=>md5($this->input->post('user_password')), 'user_age'=>$this->input->post('user_age'), 'user_mobile'=>$this->input->post('user_mobile') ); print_r($user); $email_check=$this->user_model->email_check($user['user_email']); if($email_check){ $this->user_model->register_user($user); $this->session->set_flashdata('success_msg', 'Registered successfu lly.Now login to your account.'); redirect('user/login_view'); } else{ $this->session->set_flashdata('error_msg', 'Error occured,Try agai n.'); redirect('user'); } }
4.4 – login_view() In this method we will load the login form view. see the code below. public function login_view(){ $this->load->view("login.php"); }
4.5 – login_user()
http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
6/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
Through this method user will login into his account. First user enters his email and password into the login form.All the input fields now will be catch in this method and then send these values into the model method login_user method to verify and fetch the records for this specific user from the MySQL database.When all the records will be fetched then we will save them in our session so we can use them for the profile dashboard. function login_user(){ $user_login=array( 'user_email'=>$this->input->post('user_email'), 'user_password'=>md5($this->input->post('user_password')) ); $data=$this->user_model->login_user($user_login['user_email'],$u ser_login['user_password']); if($data) { $this->session->set_userdata('user_id',$data['user_id']); $this->session>set_userdata('user_email',$data['user_email']); $this->session>set_userdata('user_name',$data['user_name']); $this->session->set_userdata('user_age',$data['user_age']); $this->session->set_userdata('user_mobile',$data['user_mobil e']); $this->load->view('user_profile.php'); } else{ $this->session->set_flashdata('error_msg', 'Error occured,Tr y again.'); $this->load->view("login.php"); } }
4.6 – user_profile() In this method we will load the user_profile interface. function user_profile(){ $this->load->view('user_profile.php'); }
4.7 – user_logout()
http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
7/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
When user will hit this method so all the session data set for the current user will be destroyed. public function user_logout(){ $this->session->sess_destroy(); redirect('user/login_view', 'refresh'); }
4.8 – Complete code for User Controller
5 – User Model Now we will explain the User Model for the login registration codeigniter script. 5.1 – Go to the project folder and in the application>>model folder create a file named User_model.php and paste the below code and save it. http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
9/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
So now create a class with the same name of the file and extends it from the CI_model. 5.2 – register_user() This the register_user() method of the User_model in which all the inputs collected from the form will be saved using CodeIgniter SQL query into the MySQL Database. public function register_user($user){ $this->db->insert('user', $user); }
5.3 – login_user() In the login_user() method email and password will be sent through the controller method and fetch the specific user data through the SQL CodeIgniter queries. public function login_user($email,$pass){ $this->db->select('*'); $this->db->from('user'); $this->db->where('user_email',$email); $this->db->where('user_password',$pass); if($query=$this->db->get()) { return $query->row_array(); } else{ return false; } }
5.4 – email_check()
http://www.phpcodify.com/codeigniter-login-registration-system-using-mysql-bootstrap/
10/18
3/8/2017
CodeIgniter Login Registration System using MySQL Bootstrap - PHPCodify
This email_check() method used to check that if the registering email is already registered or not. public function email_check($email){ $this->db->select('*'); $this->db->from('user'); $this->db->where('user_email',$email); $query=$this->db->get(); if($query->num_rows()>0){ return false; }else{ return true; } }
5.5 – Complete code for the User_Model
6-Register.php (View) This is the interface form for registration of the user built using the bootstrap framework.The complete code for register view. Registration-CI Login Registration Registration