Yii2: Configuring different sessions for backend and frontend in Yii Advanced Application Template

You are viewing revision #1 of this wiki article.
This is the latest version of this article.

This is as an extension of this wiki by Kartik V which shows to make different enableAutoLogin cookies for frontend and backend.

What else is needed

That take us in a situation where if either the backend or frontend is already signed in, and we open another window or tab for the other, then it will get automatically signed in..

because session cookie is the same.

So, here we add session component in the backend and frontend configuration file. In addition, we need to make custom folders named 'tmp' (or whatever name suits you) in the backend folder and frontend folder respectively.

Backend Config
'components' => [
		'session' => [
			'name' => 'PHPBACKSESSID',
			'savePath' => __DIR__ . '/../tmp',
		],
    ],
Frontend Config
'components' => [
		'session' => [
			'name' => 'PHPFRONTSESSID',
			'savePath' => __DIR__ . '/../tmp',
		],
    ],

Now, you can have different sessions for frontend and backend in the same browser.