duanrong0738 2017-09-07 09:56
浏览 27
已采纳

多个用户登录到现有的Codeigniter项目

I have developed a website which have single login access. I want to give different login access to different members. I tried a sample project as Mutiuser in which there are multiple login, but in this I'm unable to integrate my project. Its showing 404 error after login, in url

http://localhost/Multi_user/login/validate

i have added My_Controller.php in application/core folder After this im gettin 404 page not found

My_Controller.php

<?php 

class MY_Controller extends CI_Controller 
{
    public function __construct()
    {
        parent::__construct();
    }

    public function isLoggedIn()
    {
        $this->load->library('session');

        if($this->session->userdata('logged_in') === true) {
            redirect('../dashboard');
        }
    }   

    public function isNotLoggedIn()
    {
        $this->load->library('session');

        if($this->session->userdata('logged_in') !== true) {
            redirect('../../');
        }
    }

}

this is login.php present application/controllers folder

class Login extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

           $this->load->model('login/login_model');         

    }
    /*
    *Showing  Login page here 
    */
    function index()
    {

        $this->load->view('login/login'); 
    }


    /**
    * check the username and the password with the database
    * @return void
    */

    function validate()
    {  


         $username = $this->input->post('username');
         $password = $this->input->post('password');

         $is_valid = $this->login_model->validate($username, $password);




         if($is_valid)/*If valid username and password set */
         {
             $get_id = $this->login_model->get_id($username, $password);                

            foreach($get_id as $val)
                { 
                        $id=$val->id;
                     $name = $val->username;                  
                     $password = $val->password;                 
                     $type=$val->type;

                     if($type=='admin')
                     {
                        $data = array(
                        'admin_name' =>$name, 
                        'admin_password' => $password,
                        'admin_type'=>$type,
                        'admin_id'=>$id,
                        'is_logged_in' => true
                        );
                          $this->session->set_userdata($data); /*Here  setting the Admin datas in session */
                          redirect('admin/dashboard');
                     }
                    if($type=='staff')
                     {

                        $data = array(
                        'staff_name' =>$name, 
                        'staff_password' =>$password,
                        'staff_type'=>$type,
                        'staff_id'=>$id,
                        'staff_is_logged_in' => true
                        );
                          $this->session->set_userdata($data); /*Here  setting the  staff datas values in session */
                          redirect('staff/dashboard');
                     }
                     if($type=='student')
                     {
                        $data = array(
                        'admin_name' =>$name, 
                        'admin_password' => $password,
                        'admin_type'=>$type,
                        'admin_id'=>$id,
                        'is_logged_in' => true
                        );
                          $this->session->set_userdata($data); /*Here  setting the Admin datas in session */
                          redirect('student/dashboard');
                     }


            }       


        }
        else // incorrect username or password
        {


            $this->session->set_flashdata('msg1', 'Username or Password Incorrect!');
            redirect('login');
        }

    }

    /**
        * Unset the session, and logout the user.
        * @return void
    */      
    public function admin_logout()
    {

                $array_items = array(
                'admin_name', 
                'admin_password',
                'admin_type',
                'admin_id',
                'is_logged_in',
                );



        $this->session->unset_userdata($array_items);
         $this->session->set_flashdata('msg', 'Admin Signed Out Now!');
            redirect('login');


    }

    public function staff_logout()
    {
            $array_items = array(   

                        'staff_name',
                        'staff_password' ,
                        'staff_type',
                        'staff_id',
                        'staff_is_logged_in'
                        );



        $this->session->unset_userdata($array_items);
         $this->session->set_flashdata('msg', 'Staff Signed Out Now!');
            redirect('login');


    }

Public function next_demo()
{
  $this->load->view('next_demo');

}



}    
  • 写回答

1条回答 默认 最新

  • dongtou2097 2017-09-07 10:17
    关注

    Always there is two way to get the solution forward and backward process. In Forward Process: Create a replica of your sample project step by step, it will help you to debug your issue. Backward Process: Just remove all unwanted code to get attention on your desired code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退