I used database session storage approach for using my sessions,
And I used this article too: slow-db-session-table
So I created YiiSession
table in my db with this script:
CREATE TABLE YiiSession
(
id CHAR(32) PRIMARY KEY,
expire INTEGER,
data BLOB,
KEY expire_idx (expire) USING BTREE
);
And my config in config/main.php:
'session' => [
'class' => 'CDbHttpSession',
'connectionID' => 'db',
'sessionTableName' => 'YiiSession',
'timeout' => 3600 * 24 * 30,
'autoStart' => false,
'autoCreateSessionTable' => false
],
I stores all user cart info session values as an object like this:
Yii::app()->session[‘user-cart’] = $this->cartInfo;
Issue
There are some issues,
1- Session, after page redirect sometimes no have any value,there is this problem
with using CDbHttpSession and no in session file working approach.
2- Sometimes session stores but unset session not works, and maybe after calling two
more time the method clears sessions it works.
unset(Yii::app()->session[‘user-cart’]);
What is the problem?
I don’t have any problem with working with session file approach, but db session not working correctly in my codes.
Yii version -> 1.1.23
PHP version -> 7.4