Welcome Guest, Not a member yet? Register   Sign In
Odd behaviour with session library, new DB session entry created on every page load
#1

[eluser]aj2000[/eluser]
Hello

I'm quite new to Code Igniter although a fairly experienced PHP developer. I'm trying to get used to the CI session library but keep running into a strange problem.

First some config settings;

$config['base_url'] = "http://andrewj.absrvex03.alanblunden.co.uk";
$config['index_page'] = "index.php";

$config['sess_cookie_name'] = 'MY_CUSTOM_COOKIE_NAME';
$config['sess_expiration'] = 3600;
$config['sess_encrypt_cookie'] = TRUE;
$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;

$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";

With the above settings i also 'Autoload' the sessions class on every page.

The problem is this. Every time i navigate to a new page in the same browser, a new session cookie is a set and a new DB entry inserted into the ci_sessions table. What i am trying to achieve is, after a user logs in, I store some DB results to the session class then redirect to a new page. When the new page loads however a new session is created. The data i am trying to store does get stored in the DB but because a new session is created, that data in the DB is no longer available. For example

//log in

if ($this->form_validation->run() == FALSE)
{
//error
}
else
{
// process login - get some DB key/value pairs and store to session
$query = $this->db->query("SELECT SOME SQL STUFF");

if ($query->num_rows() > 0) {
$data = $query->row_array();
$this->session->set_userdata($data);
redirect('/controlpanel', 'location', 301);

}
else {
//error
}

//on next page in controller
var_dump($this->session->userdata('session_id'); //show up with newly generated session_id
var_dump($this->session->userdata('user_name')); //returns false as no data in DB

Strangely if i insert a very short array into the session data, the value shows up. However my understanding of the DB implementation is that you can store 4kb in a cookie but as much as you want in the DB and STILL be able to read whats in the DB using $this->session->userdata('');

The main issue is why do i end up with a new session entry in the DB whenever i change page?

Any help would be much appreciated as although I like the look and feel of CI, this is an immediate show stopper. Im am using FF3.

Thanks
#2

[eluser]n0xie[/eluser]
Can you show us with help of the profiler what session information is retrieved? (i.e. the queries run by the session class)




Theme © iAndrew 2016 - Forum software by © MyBB