I am having a small login problem with codeigniter, after logging in it does not transfer the data through the session. I did the following tests:
- I printed the session on the controler [ok, printed correct data]
- I printed the session in another controler [did not print anything]
- I cleaned Cache
public function login(){ $usuario = $this->input->post('usuario'); // recebe name usuario pelo post $senha = $this->input->post('senha'); $this->db->where('usuario', $usuario); // pega o valor igual ao usuario do post no banco $this->db->where('senha', $senha); $this->db->where('ativo',1); $usuario = $this->db->get('usuarios')->result(); if (count($usuario)===1) { $dados = array( 'usuario'=>$usuario[0]->usuario, 'logado'=> TRUE ); $this->session->set_userdata($dados); //print_r($dados); redirect('administracao/categorias'); }else{ echo heading('Usuario não encontrado', 2); } }
Login verification:
class Categorias extends CI_Controller{ public function __construct(){ parent::__construct(); if (!$this->session->userdata('usuario') || !$this->session->userdata('logado')) { redirect('administracao/home'); } }