CodeIgniter Forums
CI session not working properly - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: CI session not working properly (/thread-7505.html)



CI session not working properly - El Forum - 04-11-2008

[eluser]manash007[/eluser]
I have this configuration:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;

I am getting session value first time. But in next i am not getting session value....
anbody help me


CI session not working properly - El Forum - 04-12-2008

[eluser]zeratool[/eluser]
im not using it actually, im using the "Native_session" class for session handling, you can get it here:

http://codeigniter.com/wiki/Native_session/

it's fast IMO.


CI session not working properly - El Forum - 04-12-2008

[eluser]Derek Allard[/eluser]
you'll need to tell us a bit more about what isn't working in order for us to help.


CI session not working properly - El Forum - 04-12-2008

[eluser]manash007[/eluser]
when i am write the data in a session it is working fine........
but in case of reading session data first time i am getting the session data...
after first time there is no value in the session...
that is in second time posting the value may be replaced by null....
what would be the reason???????????


CI session not working properly - El Forum - 04-12-2008

[eluser]Derek Allard[/eluser]
If you use just the code in the docs, does it work?

If you want, you can post some code.


CI session not working properly - El Forum - 04-12-2008

[eluser]manash007[/eluser]
This is my Login function:
Code:
function login(){
        $header_data=array();
        $this->load->model('headmodel');
        $header_data=$this->headmodel->getHeaderData();
        $output=$this->load->view('header',$header_data,true);        
        
    
        
        if($this->input->post('submit')){
            //var_dump($this->input->post('password'));
            $this->load->library('validation');
          
            $rules['username'] = 'trim|required|callback_checklogin';
            $rules['password'] = 'trim|required';
            $this->validation->set_rules($rules);

            $fields['username']   = 'User Name';
            $fields['password']  = 'Password';

            $this->validation->set_fields($fields);
            if($this->validation->run()==FALSE){
        
                $output.=$this->load->view('user/user_login',$header_data,true);
            }else{                
                
                $output.=$this->load->view('user/user_nav',$header_data,true);        
                $output.=$this->load->view('user/user_account',$header_data,true);
                
            }
        }else{

        $output.=$this->load->view('user/user_login',$header_data,true);
        }        
        $output.=$this->load->view('footer',$header_data,true);
        $this->output->set_output($output);
        }

And my callback function is:::::

function checklogin(){
        $uname = $this->input->post('username');
        $pass = $this->input->post('password');
        $password = md5($pass);
        
        $this->db->where('username',$uname);
        $this->db->where('password',$password);
        $query = $this->db->get('user');
        
        if($query->num_rows()){
            $user = $query->result();
            $this->session->set_userdata('user',$user);
            return true;
        }else{
            $this->validation->set_message('checklogin','User Name and Password do not match');
            return false;
        }
    }



CI session not working properly - El Forum - 04-12-2008

[eluser]Derek Allard[/eluser]
Could I trouble you to reduce this down to session only code?


CI session not working properly - El Forum - 04-12-2008

[eluser]manash007[/eluser]
From where i am writing in the session:
Code:
if($query->num_rows()){
$user = $query->result();//*************************
$this->session->set_userdata(’user’,$user);//*********************
return true;
}else{
$this->validation->set_message(’checklogin’,’User Name and Password do not match’);
return false;
}

where i am trying to read session data:
<?php
$userdata1 = $this->session->userdata('user');
$userdata = $userdata1[0];

var_dump($userdata);

?>



CI session not working properly - El Forum - 04-13-2008

[eluser]Derek Allard[/eluser]
Its not that I can't read your code, its that I want to reduce the problem down to only the session so that we can squarely say "the session isn't working". For example, in the code you gave me above, if $user was set to "NULL", then it would be passing a null value, and this would explain the symptoms you see.

In your case above, you are setting a session with the value of $user, but I don't see your user variable defined. I do see a $uname, but don't know where $user is coming from. This is probably the error.

The reason I was trying to get you to reduce down is that you could see that session is working, and focus on why the value isn't getting passed as expected.

Good luck, and welcome to CodeIgniter!