Welcome Guest, Not a member yet? Register   Sign In
codeigniter sessions and database
#1

[eluser]mysterious[/eluser]
I am using CI's session library for loging in/out users in my application. After watching a security tutorial I realized I should use session library with database. So i created a users table in database and set $config['sess_use_database'] = true; in config file.

After doing this change i m not able to log into application. Then I opened user's table in database and realized that user_data field is empty while other fields have data. I used different browsers every time there is an entry in database but no data in user_data field.

my controler code is.

Code:
function checkLogin()
    {
        $username=$this->input->post('username');
        $password=sha1($this->input->post('password'));
        
        $this->db->select('userId, type, username');
        $this->db->where(array('username' => $username, 'password'=>$password));
        $check=$this->db->get('users')->row_array();
        
        if(count($check)>0)
        {    
            $sessiondata=array('userid'=>$check['userId'],'usertype'=>$check['type'],'username'=>$check['username']);
            $this->session->sess_destroy();
            $this->session->set_userdata($sessiondata);
            redirect('klass');
        }    
        else
            echo 'Wrong Username and Password';
    }
#2

[eluser]WanWizard[/eluser]
You're destroying the session, so where should the userdata be stored? The session no longer exists...
#3

[eluser]mysterious[/eluser]
I wanted to destroy all existing sessions before starting new one. why same code works fine without database?
#4

[eluser]InsiteFX[/eluser]
WanWizard is correct!

Because witout database it's using cookies!

InsiteFX
#5

[eluser]mysterious[/eluser]
yes WanWizard was right and my problem sorted out. but i was thinking how a session is destroyed before its creation?
#6

[eluser]InsiteFX[/eluser]
Look at the session class then you will understand what it is doing!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB