Display username logged in with Codeigniter

Asked

Viewed 292 times

1

How do I display the username logged in to the system?

The function that authenticates and creates the session is this:

function verificar()
{
    $this->load->model('tbdaluno');
    $check = $this->tbdaluno->validar();
    if($check)
    {
        $this->session->set_userdata('aluno', $check);
        redirect('dashboard');
    }
    else
    {
        redirect('');
    }
}
  • And friend with the same problem, managed to solve? if yes help us solve, I need to display the user name with the session as well and I can’t. Hug

1 answer

0

Within your condition of if/else creates a variable for the SESSION which was set, and passes the variable in the $load, or in a very rustic way, in its View use $_SESSION['aluno'].

function verificar()
{
    $this->load->model('tbdaluno');
    $check = $this->tbdaluno->validar();
    if($check)
    {
        $dados['aluno'] = $this->session->set_userdata('aluno', $check);
        redirect('dashboard',$dados);

    }
    else
    {
        redirect('');
    }
}
  • Correia de Andrade Could you give us an example? , I’m a beginner in php codeigniter and to with the same problem, I need to display the session user name but I can’t.

  • @Joana, the way I used above makes it possible to use $_SESSION in your view... Example in your view html, will you open the call php <?php echo $_SESSION['student']? >, this way you will be able to show on the screen the user of that session.

  • Okay, thank you very much, I’ll try here. VLW

Browser other questions tagged

You are not signed in. Login or sign up in order to post.