how to display username in header using session - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: how to display username in header using session (/showthread.php?tid=67901) |
how to display username in header using session - sumant - 04-21-2017 hello... i want to display username in header using session but when i use ($this->session->userdata this i get '1' . please help me how to do it. login controller: public function admin_login(){ $this->load->library('form_validation'); $this->form_validation->set_rules('username','USER NAME','required|alpha|trim'); $this->form_validation->set_rules('password','PASSWORD','required'); //$this->form_validation->set_error_delimiters("<p class='text-danger'>","</p>"); if($this->form_validation->run('admin_login')){ $username = $this->input->post('username'); $password = $this->input->post('password'); $this->load->model('loginmodel'); $login_id = $this->loginmodel->login_valid($username,$password); if($login_id){ //$this->load->library('session'); $this->session->set_userdata('user_id',$login_id); return redirect('admin/dashboard'); } else{ $this->session->set_flashdata('login_failed','Invalid Username/Password'); return redirect('user'); } }else{ //echo"not login"; $this->load->view('public2/login_form'); //echo validation_errors(); } ///login model: public function login_valid($username,$password){ $q=$this->db->where(['uname'=>$username,'pword'=>$password]) ->get('users'); if($q->num_rows()){ return $q->row()->id; //return TRUE; } else{ return false; } } RE: how to display username in header using session - Martin7483 - 04-21-2017 You get 1 because you are setting the user_id with the value of $login_id and not the username with the value of $username PHP Code: $this->session->set_userdata('user_id',$login_id); So also set the username PHP Code: $this->session->set_userdata('username',$username); And what type of value is returned for $login_id? RE: how to display username in header using session - sumant - 04-22-2017 (04-21-2017, 08:27 AM)Martin7483 Wrote: You get 1 because you are setting the user_id with the value of $login_id and not the username with the value of $username i did this($this->session->set_userdata('username',$username) as well but not working... |