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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看