CDHttpSesion

How can i store values in between requests?

i am using:


								     'session' => array(

                                                            'class'=>'CDbHttpSession',

                                                            'sessionTableName' => 'internalsessions',

                                                            'timeout' => 86400,

                                                            'connectionID' => 'db',

                                                        ),

By just placing this any were in my code:


print_r(Yii::app()->session);

a record is created in the session table with an empty data, If i hit refresh button another one is created and so on…

How can i make a record to be persistent for each user? if i do this:


Yii::app()->session['test'] = 'test'; 

It saves a new record for each refresh i make, when will it clear those inserted records? how can i make it so it will add only one record per member per session item?

Thanks.

I would start debugging by specifying cookieMode to ‘only’. You should be aware that the current implementation will store each session as a single row by serializing session data.

That’s the problem, I don’t want it to store a new record each time it is called. I would like it to be distinct on a member basis and on a key basis so if i call:

Yii::app()->session[‘test’] = ‘test’;

Yii::app()->session[‘test’] = ‘test1’;

twice it will first store the first instance then override it with the second one. Then i will have ‘test1’ in that record in the DB. And it will only create one record for each session key for each member.

In other words, how can i store something that will exists in between requests?

I believe your problem is related to session id. Maybe you misconfigured your session cookie, so a new session is instantiated each time your browser sends a request.

Could you provide with a demo on how to use it to achieve what i am looking for?

Thanks.




'session' => array(

    'class'=>'CDbHttpSession',

    'sessionTableName' => 'internalsessions',

    'timeout' => 86400,

    'connectionID' => 'db',

    'cookieMode' => 'only',

),



Empty browser cache and clear session table before testing.

Did that, It saves the stuff in the DB but always adds a new row, the ids in the db doesn’t match the cookie i have

Using a browser extension you may want to investigate what cookies are received and sent back and forth between the browser and the server.

I also explicitly set sessionName to ‘S’ to recognize it easier.

OK i did that, and i found out that the session value saved in the cookie does not match the ids in the database. and when ever i call the Yii::app()->session it creates a record in the DB. i think it’s because the cookie and the id in the DB are not matched.

I still can’t get it to work, I tried using just the CHttpSession with no luck. it doesn’t save the session.

ok figured it out. Just needed to preload it first for it to work.