Welcome Guest, Not a member yet? Register   Sign In
how to display username in header using session
#1

hello... i want to display username in header using session but when i use ($this->session->userdataWink 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;
}
}
Reply
#2

(This post was last modified: 04-21-2017, 08:30 AM by Martin7483.)

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?
Reply
#3

(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
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?

i did this($this->session->set_userdata('username',$username)Wink as well  but not working...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB