Yii2 中实现单点登录的方法
程序员文章站
2022-04-22 08:51:42
本文介绍了yii2 中实现单点登录的方法,分享给大家,具体如下:
修改 /common/config/main.php
一、在 config 头部上加上以下代码...
本文介绍了yii2 中实现单点登录的方法,分享给大家,具体如下:
修改 /common/config/main.php
一、在 config 头部上加上以下代码
<?php // session 跨域 $host = explode('.', $_server["http_host"]); if (count($host) > 2) { define('domain', $host[1] . '.' . $host[2]); } else { define('domain', $host[0] . '.' . $host[1]); }
二、在 config 的 components 配置中加入
<?php 'user' => [ 'identityclass' => 'common\models\user', 'enableautologin' => true, 'identitycookie' => ['name' => '_identity', 'httponly' => true, 'domain' => '.'.domain], ], 'session' => [ 'cookieparams' => ['domain' => '.'.domain, 'lifetime' => 0], 'timeout' => 3600, ],
三、controller 中使用
<?php //设置 yii::$app->session['var']='value'; //使用 echo yii::$app->session['var']; //移除 unset(yii::$app->session['var']);
四、测试
4.1 www.aaa.com 登陆
4.2 www.bbb.com session 依然有效果。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: python构建深度神经网络(DNN)