Yii中配置单点登录 即多个子站同步登录。

来源:互联网 发布:发型知乎女生短发 编辑:程序博客网 时间:2024/06/07 09:27

转 http://blog.csdn.net/a605356316/article/details/7771642


以下配置文件在config.php中,所有需要同步的站点都需要填写。网上一些站点给出的有的只是一部分,导致我走了很多弯路,经过N次测试后,确定以下方案是完美的。

[php] view plaincopyprint?
  1. 'components'=>array(  
  2.     'user'=>array(  
  3.         //'class'=>'CWebUser',//你可以自定义你的Cwebuser  
  4.         'identityCookie'=>array('domain' => '.domain.cc','path' => '/'),//配置用户cookie作用域  
  5.         // enable cookie-based authentication  
  6.         'allowAutoLogin'=>true,//允许同步登录  
  7.         'stateKeyPrefix'=>'yourprefix',//你的前缀,必须指定为一样的  
  8.         'loginUrl'=>array('/user/login'),  
  9.     ),  
  10.     'session' => array(  
  11.         'cookieParams' => array('domain' => '.domain.cc''lifetime' => 0),//配置会话ID作用域 生命期和超时  
  12.         'timeout' => 3600,  
  13.         //这里千万不要指定cookieMode => none,否则无法对应sessionid导致无法登录,更别说同步了。(有些不负责的博客竟然说同步登录需要设定这个属性为none!!!!太坑爹了。。。)  
  14.     ),   
  15.     'statePersister'=>array//指定cookie加密的状态文件  
  16.         'class'=>'CStatePersister',//指定类       
  17.         'stateFile'=>'../CommonLib/protected/runtime/state.bin',//配置通用状态文件路径,注意,如果你的站点是分布式的,你必须把该文件复制一份到不同服务器上,否则无法跨域。因为里面有个通用密钥,密钥不同则无法验证身份。  
  18.     ),  


再啰嗦一句 protect/runtime目录的权限必须是777


ok,这应该是最完美的方案。


补充:

1、不能再本地使用localhost测试,必须放到站点上;

2、'stateFile'=>'../CommonLib/protected/runtime/state.bin', 根据自己的情况设置。