Very strange problem. The fact is that a couple of months ago I had a situation that when using DbSession I needed to identify unregistered users using a regular session (so that the administrator could log in to the admin area), the problem was not solved until I added the component session use cookies 'useCookies' => true . At the moment it has stopped working even with the use of cookies. It is possible that it could break due to changes in some configurations in the application (for example, changing the version of php 7.0 to 7.1). Any options and guesses fit, because at the moment I do not even know which way to dig. I really need help.

Here are the configurations of my DbSession:

  'session' => [ 'class' => 'yii\web\DbSession', 'useCookies' => true, 'timeout' => 60 * 60, // 1 hour 'writeCallback' => function ($session) { // <удаляю повторяющиеся записи> return [ 'user_ip' => Yii::$app->request->userIP, 'user_id' => Yii::$app->user->id, 'last_write' => time(), ]; }, ], 

Here is my previous question , if you want to get acquainted in more detail.

  • So you have to pester. View the fact of adding a record to the database and the fact that the cookie has been saved by the user in the browser. Just in case, once again re-read the documentation section and check how the application is configured. - fedornabilkin
  • @fedornabilkin add a record to the database is, cookies are added. Just because the user is not identified, the record and cookie are overwritten and the data in the session is lost. - Human
  • And why is it not identified? The user comes to the site, the server generates the code and saves it to the database (or to a file), then sends a cookie to the browser, which can be used to find the generated code. If the cookie does not match the record, then either they are different, or the cookie's lifetime is short. - fedornabilkin
  • @fedornabilkin look, everything is recorded when necessary, but as soon as the redirect occurs, the data is not recognized and overwritten. Suppose you are not using a regular session when using DbSession, how can I check what could be the problem? - Human
  • I think we should try without the database, try different cookie settings (lifetime, domain, validation). - fedornabilkin

0