Welcome Guest, Not a member yet? Register   Sign In
NEVER MIND!!! was: Database Session does not update user_id -
#1

[eluser]Jay Turley[/eluser]
Hi all-

searched the forums but couldn't find an answer to this so I'm gonna throw it out there...

I have configured my CI sessions to use the database. While I can login and out of my application, the user_id field in the database is never updated with the user id loaded from the database.

The login code is as follows:

Code:
$conditions = array(
    'username' => $this->input->post('username',TRUE),
    'password' => dohash($this->input->post('password')),
);

$this->db->select('id');
$query = $this->db->getwhere('users', $conditions, 1, 0);
if ($query->num_rows != 1) {
    $this->load->view('login_fail');
} else {
    $row = $query->row();
    $this->session->set_userdata(array('user_id'=>$row->id));
    $this->load->view('login_success');
}

My config file has the following pertinent code:

Code:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update'] = 300;

No matter what I do, the ci_sessions table always contains user_id = 0

From my limited understanding, enabling the database for sessions should not change the working of any of the session functions.

Can anyone tell me where I have gone wrong? Let me know if you need more code...

Thanks!
#2

[eluser]Jay Turley[/eluser]
As an aside, I just noticed that the logged_in field never changes in the ci_sessions table either. It just stays set to 0.

This pretty much indicates to me I forgot something fundamental, but I just can't find it.
#3

[eluser]Jay Turley[/eluser]
Okay, my problem is that I was using a ci_sessions table with extra fields from some other piece of code I had tested. user_id and logged_in: those values aren't even included in the standard session info... sigh...




Theme © iAndrew 2016 - Forum software by © MyBB