Seach

simple login example in codeigniter

set
$autoload['libraries'] = array('database'); ,$autoload['helper'] = array('url','form');
set database.php database entries like hostname,user,password,databasename
create a controller entry.php


<?php
defined("BASEPATH") OR exit("Dirret Sript Not Allowed");
class Entry extends CI_Controller
{
  function __construct()
  {
      parent::__construct();
  } 
  public function index()
  {
      $this->load->view("entryview");
  }
  public function login()
  {
      $this->load->model("entrymodel");
      $status=$this->entrymodel->validate();
     
      if($status==1)
      {
          redirect("member");
      }
      else
      {
          echo "invalid user";
      }  
  }
   public function signin()
   {
       $this->load->view("create_new_user");
      
   }
   public function register()
   {
       $this->load->model("create_new_user_model","obj");
       $status=$this->obj->create();
       if($status)
       {
           redirect("entry");
       }
   }
}


?>


create  a model entrymodel.php


<?php
defined("BASEPATH") OR exit("Dirrect Access Not Allowed");
class Entrymodel extends CI_Model
{
   
    function __construct() {
        parent::__construct();
    }
   
    public function validate()
    {
        $this->db->where('email',  $this->input->post('emailid'));
        $this->db->where('password',  $this->input->post('password'));
        $query=$this->db->get('login');
        return $query->num_rows();
    } 
}
?>


create a view page create_new_user.php


<form method="post"  action="<?php echo site_url("entry/login")?>" >
      <table border="1">
          <tr>
              <td>
                  <label>UserId</label>
              </td>
              <td>
                  <input type="text" name="emailid">
                 
              </td>
          </tr>
          <tr>
              <td>
                  <label>
                      Password
                  </label>
              </td>
              <td>
                  <input type="text" name="password">
                 
              </td>
             
          </tr>
          <tr>
              <td>
                  <input type="submit" name="submit" value="Login">
              </td>
              <td>
                  <a href="<?php echo base_url(); ?>index.php/entry/signin">Register</a>
                 
              </td>
          </tr>
    </table>