Seperate backend and frontend sessions Yii2

We are configuring different identity cookies and sessions for your user component for frontend and backend.
identityCookie property

Add user and session property arrays in file backend\config\main.php in components array (FOR BACKEND)

'user' => [
	'identityClass' => 'common\models\User',
	'enableAutoLogin' => true,
	'identityCookie' => [
		'name' => '_backendUser', // unique for backend
		'path'=>'/backend/web'  // correct path for the backend app.
	],
],
'session' => [
	'name' => '_backendSessionId', // unique for backend
	'savePath' => __DIR__ . '/../runtime', // a temporary folder on backend
],

Add user and session property arrays in file frontend\config\main.php in components array (FOR FRONTEND)

'user' => [
	'identityClass' => 'common\models\User',
	'enableAutoLogin' => true,
	'identityCookie' => [
		'name' => '_frontendUser', // unique for frontend
		'path'=>'/frontend/web'  // correct path for the frontend app.
	],
],
'session' => [
	'name' => '_frontendSessionId', // unique for frontend
	'savePath' => __DIR__ . '/../runtime', // a temporary folder on frontend
],
Share

You may also like...