Welcome Guest, Not a member yet? Register   Sign In
Help with SESSION.
#1

[eluser]Yakow[/eluser]
Hello dudes!
Im new in CI, so i have a basic question and need help.

is the basic login system, so, in my home.php i put this code:

Code:
function login(){
  $this->load->library('form_validation');
  $this->load->library('session');  
  $config = array(
                array(
                      'field'=>'login',
                      'label'=>'Login',
                      'rules'=>'required|min_length[4]|max_length[10]| htmlspecialchars'
                ),
     array(
                      'field'   => 'senha',
                      'label'   => 'Senha',
                      'rules'   => 'required| min_length[4]| max_length[10]| htmlspecialchars'
                )
              );
        $this->form_validation->set_rules($config);
  
  if($this->form_validation->run() == FALSE){
   $this->index();
  }
  else{
  
   $data['login'] = $this->input->post('login');
   $data['senha'] = $this->input->post('senha');    
  
   $this->load->model('administracao/usuarios_model');
   $login = $this->usuarios_model->login($data);
  
   if(count($login)>0){
    
    $newdata = array(
     'nome_usuario' => $login[0]->nome,
                    'usuario'  => $data['login'],
                    'loggedin' => TRUE
    );
    
    
    $this->load->library('session');
    $this->session->set_userdata($newdata);
    print_r($this->session->all_userdata());  
    redirect('administracao/produtos');
   }
   else{
    $this->index();
   }
  }

When i print "print_r($this->session->all_userdata());" i can recive $newdata...

So when i go another controller "produtos", i have this code:

Code:
function __construct(){
  parent::__construct();
  $this->load->library('session');
  $this->load->helper('conversor_de_formatos');
  
  print_r($this->session->all_userdata());  
  
        if(!$this->session->set_userdata('loggedin')){
   echo "Error.";
   exit;
        }
  
  
}

So, when i print print_r($this->session->all_userdata()); i can't get the information came from $newdata in home controller, and i can't get the view.

Why ??

Sorr for my english.


Messages In This Thread
Help with SESSION. - by El Forum - 06-04-2012, 08:21 AM
Help with SESSION. - by El Forum - 06-04-2012, 08:37 AM
Help with SESSION. - by El Forum - 06-04-2012, 09:42 AM
Help with SESSION. - by El Forum - 06-04-2012, 10:04 AM
Help with SESSION. - by El Forum - 06-04-2012, 10:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB