Welcome Guest, Not a member yet? Register   Sign In
[RESOLVED] CI 2.0.2 Sessions Using Database Are Completely Broken
#1

[eluser]Vheissu[/eluser]
Using the latest version of Codeigniter 2.0.2, the sessions library using the database for storage is broken. Basically you set a session value and it deletes itself on page load like flashdata even though normal sessions are being used.

Upon inspecting the database, it looks like a new entry in the ci_sessions table is created on each page load (when using Firefox), sort of like the session is regenerating and not taking the session values over with it.

When using Chrome, I notice it doesn't keep creating new ci_session database rows, but I refresh the page, see the values being set and then refresh again and see them being deleted using the below controller test code.

To test this, create a new controller called 'test.php' and use the following code. The code assumes that your database and session libraries are being autoloaded:

Code:
<?php

class Test extends CI_Controller {
    
    public function index()
    {
        if ( $test = $this->session->userdata('test') )
        {
            echo "Session found, value stored was: ",$test;
            $this->session->unset_userdata('test');
        }
        else
        {
            echo "Empty session, setting a test variable";
            $this->session->set_userdata('test', 'value');
        }
    }
    
}

**Edit**
This issue solved itself. I deleted my sessions table and recreated it, and it seemed to work.
#2

[eluser]WanWizard[/eluser]
What is your session configuration? What is the structure of the database table created?
#3

[eluser]cideveloper[/eluser]
Try increasing the sized of the user_agent field to 255

Also I think it makes sense to change user_data to at least MEDIUMTEXT
#4

[eluser]Vheissu[/eluser]
Database structure is the standard Codeigniter sessions table schema.

Code:
CREATE TABLE `ci_sessions` (
  `session_id` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  `ip_address` varchar(16) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
  `user_agent` varchar(120) COLLATE utf8_unicode_ci NOT NULL,
  `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
  `user_data` text COLLATE utf8_unicode_ci,
  PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

And my session settings are stock standard CI ones as well (except I am encrypting values).

Code:
$config['encryption_key'] = '1am7h3l337357n00b3v3r';

$config['sess_cookie_name']        = 'ci_session';
$config['sess_expiration']        = 7200;
$config['sess_expire_on_close']    = FALSE;
$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']    = 500;

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

I'll try increasing the size of the user agent field, but I'm only using Firefox 5.0 (latest), surely that wouldn't be reaching the user agent limit would it? It makes sense though because I have the match user agent option enabled (like it is by default).

**Edit**
Increasing the size of the user agent field does not work. Nothing changes, but thank you for helping. Also, setting 'sess_match_useragent' to false, also does not change anything, the session is still being emptied.
#5

[eluser]Vheissu[/eluser]
I also just realised someone else posted a thread with the same issue, but no fix was really supplied/found. http://ellislab.com/forums/viewthread/193688/




Theme © iAndrew 2016 - Forum software by © MyBB