New session for each request

In Yii2, I am using database to store sessions.

I need to store some data in session but data is available only for the current request.

In ‘session’ table in mysql I can see a new entry each time a request comes.

So I concluded that the data lost is because a new session is created each time and old session is no more accessible.

I am clueless and need help in fixing this issue.

Details:

DBSession setting:

‘session’ => [

        'class' => 'yii\web\DbSession',


        // 'db' => 'mydb',


        // 'sessionTable' => 'my_session',


    ],

Tried so far:

  • using session apis to get and set data as well as tried storing data directly in $_SESSION.

  • Opening session before storing data and reading data

  • Tried printing session id and observed with every request a new id is printed.

Screenshot of session table attached.

I installed a fresh Yii2 advance application and it is working fine.

I was suspecting ‘redirect’ to be the cause for creating multiple sessions, but in the new yii2 application that is not the case.

I redirected to another controller and still there is only one session.

:(