php Codeigniter身份验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Codeigniter身份验证相关的知识,希望对你有一定的参考价值。

<form action="<?php echo base_url(); ?>dashboard-view" id="login-validation" class="col-md-4 col-sm-5 col-xs-11 col-lg-3 center-margin" method="post">
            <h3 class="text-center pad25B font-gray text-transform-upr font-size-23">Magpie Admin <span class="opacity-80">v1.0.0</span></h3>

            <div id="login-form" class="content-box bg-default">
                <div class="content-box-wrapper pad20A">
                    <img class="mrg25B center-margin radius-all-100 display-block" src="<?php echo base_url()?>admin/assets/image-resources/logo-white.png" alt="admin-logo">
                        
                    <h3 style="color:red">
                    <?php
                    $excep = $this->session->userdata('exeption');
                    if ($excep) {
                      echo $excep;
                      $this->session->unset_userdata('exeption');
                    }
                    ?>
                  </h3>
                  <h3 style="color:green">
                    <?php
                    $msg = $this->session->userdata('message');
                    if ($msg) {
                      echo $msg;
                      $this->session->unset_userdata('message');
                    }
                    ?>
                  </h3>                

                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon addon-inside bg-gray">
                                <i class="glyph-icon icon-envelope-o"></i>
                            </span>
                            <input type="email" name="admin_email_address" class="form-control" id="exampleInputEmail1" placeholder="Enter User email">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon addon-inside bg-gray">
                                <i class="glyph-icon icon-unlock-alt"></i>
                            </span>
                            <input type="password" name="admin_password" class="form-control" id="exampleInputPassword1" placeholder="Enter User Password">
                        </div>
                    </div>
                    <div class="form-group">
                        <button type="submit" class="btn btn-block btn-primary">Login</button>
                    </div>
                    <div class="row">
                        <div class="checkbox-primary col-md-6" style="height: 20px;">
                            <label>
                                <input type="checkbox" id="loginCheckbox1" class="custom-checkbox">
                                Remember me
                            </label>
                        </div>
                        <div class="text-right col-md-6">
                            <a href="#" class="switch-button" switch-target="#login-forgot" switch-parent="#login-form" title="Recover password">Forgot your password?</a>
                        </div>
                    </div>
                </div>
            </div>

            <div id="login-forgot" class="content-box bg-default hide">
                <div class="content-box-wrapper pad20A">

                    <div class="form-group">
                        <label for="exampleInputEmail2">Email address:</label>
                        <div class="input-group">
                            <span class="input-group-addon addon-inside bg-gray">
                                <i class="glyph-icon icon-envelope-o"></i>
                            </span>
                            <input type="email" class="form-control" id="exampleInputEmail2" placeholder="Enter email">
                        </div>
                    </div>
                </div>
                <div class="button-pane text-center">
                    <button type="submit" class="btn btn-md btn-primary">Recover Password</button>
                    <a href="#" class="btn btn-md btn-link switch-button" switch-target="#login-form" switch-parent="#login-forgot" title="Cancel">Cancel</a>
                </div>
            </div>

        </form>
class Super_Admin extends CI_Controller {

  public function __construct() 
          {
            parent::__construct();
            $admin_id = $this->session->userdata('admin_id');
            if ($admin_id == NULL) 
              {
              redirect('admin', 'refresh');
              }
//      $this->load->model('super_admin_model', 'sa_model'); /*--model manual load--*/
         }
         
           public function index() 
          {
          $data['admin_maincontent'] = $this->load->view('admin/main_content', '', true);
          $this->load->view('admin/admin_master', $data);
         }
         
         
                public function logout()
          {
          $this->session->unset_userdata('admin_id');
          $this->session->unset_userdata('admin_full_name');
          $sdata = array();
          $sdata['message'] = "You are successfully Logout !";
          $this->session->set_userdata($sdata);
          redirect('admin');
         }

}
class Admin extends CI_Controller {

  public function __construct() {
    parent::__construct();
     $admin_id = $this->session->userdata('admin_id');
     if ($admin_id != NULL){
       redirect('super_admin','refresh');
     }
  }
  
  public function index() {
    $this->load->view('admin/login');
  }

  public function admin_login_check() {
    $admin_email_address = $this->input->post('admin_email_address', true);
    $admin_password = $this->input->post('admin_password', true);
//    $this->load->model('admin_model', 'a_model'); /*----- manual model load----*/

    $result = $this->Admin_model->admin_login_check_info($admin_email_address, $admin_password);

    $sdata = array();
    if ($result) {
      $data = array();
      $sdata['admin_full_name'] = $result->admin_full_name;
      $sdata['admin_id'] = $result->admin_id;
      $this->session->set_userdata($sdata);
      redirect('super_admin');
    } else {
      $sdata['exeption'] = "Your User email & User Password is invalid !!";
      $this->session->set_userdata($sdata);
      redirect('admin');
    }
  }



}
class Admin_Model extends CI_Model{
	
	public function admin_login_check_info($admin_email_address,$admin_password){
		$this->db->select('*');
		$this->db->from('tbl_admin');
		$this->db->where('admin_email_address',$admin_email_address);
		$this->db->where('admin_password',md5($admin_password));
		
		$query_result = $this->db->get();
		$result = $query_result->row();
		return $result;
	}
}

以上是关于php Codeigniter身份验证的主要内容,如果未能解决你的问题,请参考以下文章

php 用户身份验证库/框架...都有哪些选项? [关闭]

CodeIgniter 身份验证系统允许 3rd 方身份验证?

Codeigniter - 用户身份验证/登录插件/类? [复制]

Codeigniter 3.x 身份验证库?

使用LDAP身份验证的Codeigniter应用程序

Codeigniter facebook 身份验证问题