Php 代码点火器登录用户角色

Php 代码点火器登录用户角色,php,codeigniter,phpmyadmin,Php,Codeigniter,Phpmyadmin,我已经进行了正确的数据库配置、查看\ u登录,还将一些数据插入了ms\ u用户表。现在,我如何使用角色创建登录,例如 用户名、密码、角色“学生”“教师”“校长” 我找到了指南,但该网站只提供了两个信息登录,用户名和密码。在哪里添加第三个“角色”信息 这是view_login.php <html> <head> <title>Selamat datang pada QB Project </title></head> <scri

我已经进行了正确的数据库配置、查看\ u登录,还将一些数据插入了ms\ u用户表。现在,我如何使用角色创建登录,例如 用户名、密码、角色“学生”“教师”“校长”

我找到了指南,但该网站只提供了两个信息登录,用户名和密码。在哪里添加第三个“角色”信息

这是view_login.php

<html>
<head>  <title>Selamat datang pada QB Project </title></head>

<script>
    function loginsukses()
    {
            alert('Login Success');
    }
</script>

<body>
<center><h1>Selamat datang pada QB Architecture</h1></center>
<div id="form">
        <form method="POST" action="">
        <table border="1" bordercolor="gold" style="background-color:#FFFFFF" width="20%" cellpadding="2" cellspacing="4">
        <tr>
            <td class="td">Username</td>
            <td>
            <input type="text" id ="username" name ="username" class="gui" " />
            
            </td>
            
        </tr>
        
        <tr>
            <td class="td">Password</td>
            <td class="td"><input type="password" id="password" name="password" class="gui" /></td>
        </tr>
        
        <tr>
            <td class="td">Jabatan</td>
            <td class="td"><select name="jabatan" id="Jabatan" class="gui">
            <option value=“Accounting”>Accounting</option>
            <option value=“Direktur”>Direktur</option>
            <option value=”HeadDivisi”>Head Divisi</option>
            </select></td>
        </tr>
        <tr>
            <td></td>
            <td class="td">
            <input type="submit" name="submit" value="Login" class="button" onclick="loginsukses()" />          
            </td>
        </tr>
        
    </form>
</div>



</body>
 </html>
这是模型文件夹的登录功能

<?php

Class Login extends CI_Model
 {
 function login($username, $password)
 {
   $this -> db -> select('username, password, jabatan');
   $this -> db -> from('ms_user');
   $this -> db -> where('username = ' . "'" . $username . "'");
   $this -> db -> where('password = ' . "'" . MD5($password) . "'");
   $this -> db -> where('jabatan = ' . "'" . $jabatan . "'");
   $this -> db -> limit(1);
 
   $query = $this -> db -> get();
 
   if($query -> num_rows() == 1)
   {
     return $query->result();
   }
   else
   {
     return false;
   }
 }
}
?>
这是控制器文件夹中的validate_登录函数

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

class ValidateLogin extends CI_Controller {
 
 function __construct()
 {
   parent::__construct();
   $this->load->model('Login','',TRUE);
 }
 
 function index()
 {
   //This method will have the credentials validation
   $this->load->library('form_validation');
 
   $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
   $this->form_validation->set_rules('Jabatan', 'Username', rim|required|xss_clean');
 
   if($this->form_validation->run() == FALSE)
   {
     //Field validation failed.  User redirected to login page
     $this->load->view('login_view');
   }
   else
   {
     //Go to private area
     redirect('qb_main', 'refresh');
   }
 
 }
 
 function check_database($password)
 {
   //Field validation succeeded.  Validate against database
   $username = $this->input->post('username');
 
   //query the database
   $result = $this->user->login($username, $password, $jabatan);
 
   if($result)
   {
     $sess_array = array();
     foreach($result as $row)
     {
       $sess_array = array(
         'id' => $row->id,
         'username' => $row->username
       );
       $this->session->set_userdata('logged_in', $sess_array);
     }
     return TRUE;
   }
   else
   {
     $this->form_validation->set_message('check_database', 'Invalid username or password');
     return false;
   }
 }
}
?>

我对这个框架非常陌生,所以我不理解上面写的内容,但我很乐意学习,请帮助我

您需要在数据库中创建一个新列,或者…最好为其他用户信息创建一个单独的表,并使用join在您的模型CRUD函数中将它们链接在一起。不过,请看一下Tank Auth库。这比普通登录更好,从头开始注册。

所以你想赋予管理员、超级管理员、用户权限等角色!我建议检查一下哪种方法很酷。由于您是一名初学者,这将有点困难,但试一试,我还建议您看看bitauth。