duanhuayong6687 2019-04-29 00:51
浏览 63
已采纳

无法从CodeIgniter中的会话登录中获取和显示数据名称

So i wanna make some login page and then show the user name in the dashboard after login succeed. But the name won't show in the dashboard. its just blanks. there's no error notification or something. please help. thanks

I'm running on PHP 7


Auth.php Controller

public function index()
{
    $this->form_validation->set_rules('email','email',
        'trim|required|valid_email');
    $this->form_validation->set_rules('password','Password','trim|required');
    if($this->form_validation->run() == false){
        $data['title']='Login Page';
        $this->load->view('templates/auth_header', $data);
        $this->load->view('auth/login');
        $this->load->view('templates/auth_footer');
    }
    else{
        //success validation
        $this->_login();


    }

}

private function _login()
{
    $email = $this->input->post('email');
    $password = $this->input->post('password');

    $user = $this->db->get_where('user',['email' => $email])->row_array();

    if($user){
        //user active
        if($user['is_active']==1){
            //check password
            if(password_verify($password, $user['password'])){
                //if pass were right
                $data = [
                    'email' => $user['email'],
                    'role_id' => $user['role_id']
                ];
                $this->session->set_userdata('$data');
                redirect('user');

            }
            else{
                $this->session->set_flashdata('message','<div class="alert alert-danger" role="alert"> Wrong password</div>');
                redirect('auth');
            }

        }
        else{
        //
        $this->session->set_flashdata('message','<div class="alert alert-danger" role="alert"> 
            Email has not been activated</div>');
        redirect('auth');

    }

    }
    else{
        //no email in database
        $this->session->set_flashdata('message','<div class="alert alert-danger" role="alert"> 
            Email is not registered</div>');
        redirect('auth');

    }

}

User.php in controller (control for user)

public function index()
{

    $data['user'] = $this->db->get_where('user',['email' => $this->session->userdata('email')])->row_array();
    $data['title']='Dashboard - SmartStock';
    $this->load->view('user/index', $data);
}

and command for showing the data in page

index.php

  <div class="navbar-menu-wrapper d-flex align-items-stretch">

    <ul class="navbar-nav navbar-nav-right">
      <li class="nav-item nav-profile dropdown">
        <a class="nav-link dropdown-toggle" id="profileDropdown" href="#" data-toggle="dropdown" aria-expanded="false">
          <div class="nav-profile-img">
            <img src="<?= base_url('assets/'); ?>images/profile/default.png" alt="image">
            <span class="availability-status online"></span>             
          </div>
          <div class="nav-profile-text">
            <p class="mb-1 text-black"><?= $user['name']; ?></p>
          </div>
        </a>

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 CygwinPortable 中 NumPy 无法安装
      • ¥15 51单片机 用汇编语言实现方波非1:1的输出
      • ¥15 vivado如何支持多维打包数组模式
      • ¥15 请问第13题到底应该怎么做
      • ¥15 stable diffusion报错问题
      • ¥20 数据可视化综合运用 导入npz文件以及读取内容
      • ¥15 倒计时汇编语言RTC实时时钟
      • ¥15 CCS安装出现Failed to create the part's controls
      • ¥15 请问有digital Fortran编译器吗
      • ¥15 用cst怎么仿真同轴馈线