Losing Session Codeigniter

Asked

Viewed 152 times

0

Good afternoon guys, I started an internship and they gave me an Commerce to stir, it has Codeigniter (I had never touched)and a library called ion auth(for login) but when I login it sets the Session correctly, when going to the user panel where I need Session to identify the user Session appears as NULL, someone can give me a light?

if ($password === TRUE)
{
    if ($user->active == 0)
    {
        $this->trigger_events('post_login_unsuccessful');
        $this->set_error('login_unsuccessful_not_active');

        return FALSE;
    }
  //  echo '<pre>';print_r($user);echo'</pre>';
    $this->set_session($user);
    $this->update_last_login($user->id);
    $this->clear_login_attempts($identity);

    if ($remember && $this->config->item('remember_users', 'ion_auth'))
    {
        $this->remember_user($user->id);
    }

    $this->trigger_events(array('post_login', 'post_login_successful'));
    $this->set_message('login_successful');

    return TRUE;
}

When you enter this code in the controller the $_SESSION['user_id'] as NULL.

$idUser = $_SESSION['user_id'];
$qtdPedidos  = count($this->produtoscliente_model->getQtdPedidosCliente($idUser));
$qtdProdutos = $this->produtoscliente_model->getQtdProdutosCliente($idUser);
  • Codeigniter has its own library for Session, use it. It itself initializes the session. https://www.codeigniter.com/user_guide/libraries/sessions.html

  • I tried with her once, but every time she changes her page.

  • Once I had a similar problem, it was something on the server and resolved restarting (which is a shame not to know what happened). The difference that I wasn’t using any framework.

  • I was able to revolve by adding session_start(); to the index and commenting on the parts where they were called Session in the framework itself

  • I had this problem in my work as well and was incompatibility with PHP versions.

No answers

Browser other questions tagged

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