主页 > 编程 > php >

留言板(1)PHP CI 管理员登录模块代码

2019-01-17 13:52 阅读:161 来源:智宇SEO自媒体

  运行环境:win10 64位  php5.45  APache   CodeIgniter 3.1.9  mysql 5.5

  留言板(1)PHP  ci  管理员登录模块代码

  实现:管理员登录验证

留言板(1)PHP CI  管理员登录模块代码

  控制器代码

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends CI_Controller {
    public  function __construct()
    {
        parent::__construct();
        $this->load->model('admin_model');
        $this->load->library('session');
    }

    public function index()
    {
        if(!isset($_SESSION))
        {
            session_start();
        }

        if(isset($_POST['btn']))
        {
            $uname=$this->input->post('uname');
            $pwd=$this->input->post('pwd');
            $this->load->model('admin_model');
            $datalogin=$this->admin_model->logincheck($uname,$pwd);
            if($datalogin)
            {
                $sessionData = array(
                    'username'	=> $uname,
                    'logintime' => time(),
                );
                $this->session->set_userdata($sessionData);
                $username = $this->session->userdata('username');
                success('admin/main/index', '登陆成功');

            }
            else
            {
                error("用户名或密码错误");
             }

        }
        else
        {
            $this->load->view('login.html');
        }

    }
}

  模型代码

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Admin_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();

    }

    public function logincheck($uname,$pwd)
    {
        $data=$this->db->where(array('uname'=>$uname,'pwd'=>$pwd))->get('admin')->result_array();
        //$sql="SELECT * from yulyb_admin WHERE uname='{$uname}' AND pwd='{$pwd}'";
        //$query=$this->db->query($sql);
        //return ($query->result_array());
          return $data;
    }

}

  视图代码
 

<html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href=" <?php echo base_url('/static/admin/admin.css');?>"/>


</head>
<body>
<div id="m_top"></div>
<div id="login">
  <div class="l_l">
    <div class="l_l_c">
        <img src="<?php echo base_url('/static/adminimages/i_logo.gif');?>" />
      <div class="l_l_c_t">
        欢迎您选择使用XYCMS 前端采用XYCMS模板,版权属于该作者。后端php ci 智宇原创代码。
      </div>
    </div>
  </div>
  <div class="l_c">
    <img src="<?php echo base_url('/static/adminimages/l_line.gif');?>" />
  </div>
  <div class="l_r">
    <div class="l_r_form">
      <form name="login" method="post" action="<?php echo site_url('admin/login/index')?>" onSubmit="return checkform();">
      <table cellpadding="5" cellspacing="10" class="l_table">
        <tr>
          <td class="td1"><span>登录账号:</span></td>
          <td><input type="text" name="uname" class="u_input"  /></td>
        </tr>
        <tr>
          <td class="td1"><span>登录密码:</span></td>
          <td><input type="password" name="pwd" class="u_input" onfocus="this.className='input_on';this.onmouseout=''" onblur="this.className='u_input';this.onmouseout=function(){this.className='u_input'};" onmousemove="this.className='input_on'" onmouseout="this.className='u_input'" /></td>
        </tr>

        <tr>
          <td colspan="2" class="td2"><input type="submit" name="btn" value="提交" class="u_button" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重填" class="u_button" /></td>
        </tr>
        <tr>
          <td colspan="2" class="td3">友情提示:非网站管理员自觉离开此页面</td>
        </tr>
      </table>
      </form>
    </div>
  </div>
  <div class="clear"></div>
</div>
<div id="copy">
  <div class="copy"><a href="http://www.jsxyidc.com/" target="_blank">江苏鑫跃科技</a> Copyright &copy; 2015-2018 All Rights Reserved</div>
</div>
</body>
</html>