Session File And Session Database

I would like to use both type of session management in my application: filesystem and database session. So I’ve add in my protected/config/main.php components section:

            'session' => array(



              'sessiondb' => array(




Now, Yii::app()->sessiondb doesn’t work, in the sense that it doesn’t store data in YiiSession table. Moreover, YiiSession table is not created by default. Even if I create YiiSession table by hand, CDbHttpSession doesn’t store data in the table.

I’ve tried to add some data and print_r out , this is the result:



// below, the result:

CDbHttpSession Object


    [connectionID] => db

    [sessionTableName] => YiiSession

    [autoCreateSessionTable] => 1

    [_db:CDbHttpSession:private] => 

    [autoStart] => 1

    [behaviors] => Array



    [_initialized:CApplicationComponent:private] => 1

    [_e:CComponent:private] => 

    [_m:CComponent:private] => 


If I comment ‘session’ part of that config, and rename ‘sessiondb’ in ‘session’ it works. It seems that you can work only with one type of session, filesystem OR database, not with both… and component must be named ‘session’ to work.

Any idea?



Why on earth would you need both? :blink:

AFAIK, this is a design issue that should be settled before you upload. If it is secure to store on file then you go for it, else you go for db.

I can’t get your logic of using both!

OK, let’s say I want to decide to use one or other in admin space of my app. I suppose I cannot, right?

I’m not sure if you can or can’t but you have some serious design issues or you confused do you even know why do more than one session store

As write above, my first goal is to choose, in the admin page, if you want to save session in filesystem or in database. Is it possible or not?



It is possible.

You must declare a variable in top of main.php, say $sessionSystem = ‘CDbHttpSession’ or ‘CHttpSession’. In the config you put ‘session’=>array( class=>$sessionSystem, ),