Simple CodeIgniter 3 login MySQL Database – Programming

Simple CodeIgniter 3 login MySQL Database – Programming

In this post we will give you information about Simple CodeIgniter 3 login MySQL Database – Programming. Hear we will give you detail about Simple CodeIgniter 3 login MySQL Database – ProgrammingAnd how to use it also give you demo for it if it is necessary.

Today, We want to share with you Simple CodeIgniter 3 login MySQL Database Source Code.In this post we will show you PHP CodeIgniter 3 Login Form with Sessions, hear for Complete User Authentication System in CodeIgniter 3 we will give you demo and example for implement.In this post, we will learn about Login Signup page in CodeIgniter 3 with MySQL Database Source Code with an example.

Simple CodeIgniter 3 login MySQL Database Source Code

There are the Following The simple About Simple CodeIgniter 3 login MySQL Database Source Code Full Information With Example and source code.

As I will cover this Post with live Working example to develop CodeIgniter Simple Login Form With Sessions, so the codeigniter 3.1.9 documentation for this example is following below.

Another must read:  CodeIgniter Simple User Registration and Login System

 

CodeIgniter 3 Connect SQL Database

Here are the step by step to create a simple login system using PHP Based CodeIgniter 3

DATABASE Simple SQL TABLE

create DATABASE 'member_mst';
 
CREATE TABLE IF NOT EXISTS 'members' (
  'member_id' int(11) NOT NULL AUTO_INCREMENT,
  'member_fname' varchar(255) NOT NULL,
  'member_lname' varchar(255) NOT NULL,
  'email' varchar(255) NOT NULL,
  'password' varchar(255) NOT NULL,
  'created_at' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY ('member_id')
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;
--
-- Dumping data for table 'members'
--
INSERT INTO 'members' ('member_id', 'member_fname', 'member_lname', 'email', 'password', 'created_at') VALUES
(1, 'onlinecode', 'PHP', '[email protected]', '$2y$10$8mVSGv/bIGgcvCikXBPfTu7HfXMl3jqfiirtQGyRwV5bvOzNGmmLG', '2019-12-17 18:09:10');

Step 1: Download / install CodeIgniter 3.

set Config Files

application/config/config.php

$config['base_url'] = 'http://localhost:8080/';
$config['sess_save_path'] = sys_get_temp_dir();

Step 3: Config codeigniter 3 Database

Simple this step to Connect Your Database using codeigniter 3

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

application/config/database.php

$db['default'] = array(
    'dsn'    => '',
    'hostname' => 'localhost',
    'membername' => 'root',
    'password' => '',
    'database' => 'member_mst',
    'dbdriver' => 'mysqli',
         ....
        ......
    'save_queries' => TRUE
);

Step 4: create Codeigniter 3 controller

create a codeigniter 3 controller file called Member.php

Another must read:  CodeIgniter Login Registration Example Tutorial From Scratch

 

application/controllers

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Member extends CI_Controller {
 
    public function __construct() {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
        $this->load->library(['form_validation','session']);
        $this->load->database();
    }
 
    public function login() {
 
        $this->form_validation->set_rules('email', 'Email', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
 
        if ($this->form_validation->run() == FALSE) {
            $this->load->view('login_view');
        } else {
 
            $email = $this->input->post('email');
            $password = $this->input->post('password');
 
            $member = $this->db->get_where('members',['email' => $email])->row();
            
            if(!$member) {
                $this->session->set_flashdata('login_error', 'Please check your email or password and try again.', 300);
                redirect(uri_string());
            }
 
    
            if(!password_verify($password,$member->password)) {
                $this->session->set_flashdata('login_error', 'Please check your email or password and try again.', 300);
                redirect(uri_string());
            }
 
             $data = array(
                    'member_id' => $member->member_id,
                    'member_fname' => $member->member_fname,
                    'member_lname' => $member->member_lname,
                    'email' => $member->email,
                    );
 
                
            $this->session->set_memberdata($data);
 
            //simple CI_Controller 3 redirect('/'); // redirect to main auth home
            echo 'Login success!'; exit;
            
        }        
    }
 
    public function logout(){
        $this->session->sess_destroy();
        redirect('member/login');
    }
 
}

Step 5:create a login form in Codeigniter 3

login_form.php

application/views

 <div >
 
        <?php echo form_open('member/login'); ?>
 
        <div >
            <label for="email">Email address</label>
            <input type="email"  value="<?php echo set_value('email'); ?>" id="email" name="email" aria-describedby="emailHelp" placeholder="Enter Your Correct email Address">
            <?php echo form_error('email'); ?>
        </div>
        <div >
            <label for="password">Password</label>
            <input type="password"  name="password" id="Inputdatapwd" placeholder="Eneter Your Strong Password">
            <?php echo form_error('password'); ?>
        </div>
        <button type="submit" >Sign In</button>
        <?php echo $this->session->flashdata('login_error'); ?>
        
        <?php form_close(); ?>
    </div>

Step 6: Run Project

That’s it. Now head over your browser Like Mozila, Chrome..

Another must read:  PHP laravel open new tab Example Tutorial

 

 

http://localhost:8080/member/login 
Angular 6 CRUD Operations Application Tutorials

Read :

  • Technology
  • Google Adsense
  • Programming

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Simple CodeIgniter 3 login MySQL Database Source Code.
I would like to have feedback on my onlinecode blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Hope this code and post will helped you for implement Simple CodeIgniter 3 login MySQL Database – Programming. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  56  =  66

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US