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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化