要求
两个域名一个 www.shiqidu.com 、一个 store.shiqidu.com,要求用户在 www.shiqidu.com 登录后,打开 store.shiqidu.com 后直接是登录状态,不用重新登录。
实现
- 修改 www.shiqidu.com 项目的
config/main.php的identityCookie,增加domain配置。
'user' => [
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true, 'domain' => '.shiqidu.com'],
],
- 修改 store.shiqidu.com 项目的
config/main.php,跟上面一样。
'user' => [
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true, 'domain' => '.shiqidu.com'],
],
- 修改 store.shiqidu.com 项目的
config/main-local.php的cookieValidationKey
'components' => [
'request' => [
// 改为和 www.shiqidu.com 项目的一样
'cookieValidationKey' => 'JpMmgd4PC2X1bf6BpRrzVT-fjGsfZv9s',
],
],
这是最简单的做法,当然你也可以自己写代码获取 cookie,然后自己写自动登录的代码。