0

当用户打开站点并登录到站点时,我正在使用 Yii 框架www.dominname.com ,身份验证或用户会话数据不同, http://dominname.com 因此用户在打开 HTTP 时必须再次登录,我可以进行身份​​验证登录吗?在 WWW 和 HTTP 上完成或在 WWW 和 HTTP 之间共享会话数据。Yii 有什么配置可以解决这个问题吗?


如果用户检查rememberMe其他用户将不会登录,此代码对我有用有谁知道如何解决这个问题?

  1. 主/配置

      'user' => array(
        // enable cookie-based authentication
        'class' => 'WebUser',
        'allowAutoLogin' => true,
    ),
    'session' => array(
    'savePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../session',
    'cookieMode' => 'allow',
        'cookieParams' => array(
            'path' => '/',
            'domain' => '.domainname.org',
            'httpOnly' => true,
        ),
    ),
    
  2. 组件/WebUser

    class WebUser extends CWebUser {
    
      public $identityCookie = array(
     'path' => '/',
     'domain' => '.domainname.org',
      );
     public function init() {
     $conf = Yii::app()->session->cookieParams;
     $this->identityCookie = array(
        'path' => $conf['path'],
        'domain' => $conf['domain'],
     );
     parent::init();
     }
      public function logout($destroySession = true) {
      if ($this->allowAutoLogin && isset($this->identityCookie['domain'])) {
         $cookies = Yii::app()->getRequest()->getCookies();
          if (null !== ($cookie = $cookies[$this->getStateKeyPrefix()])) {
             $originalCookie = new CHttpCookie($cookie->name, $cookie->value);
              $cookie->domain = $this->identityCookie['domain'];
             $cookies->remove($this->getStateKeyPrefix());
             $cookies->add($originalCookie->name, $originalCookie);
             }
       }
      parent::logout($destroySession);
      }
     }
    
4

1 回答 1

0

除非有理由将 www 和非 www 域分开,否则最好将非 www 域的 www 重定向到另一个。此外,它对 SEO 更好。您可以通过将其添加到您的 .htaccess 文件中来做到这一点:

RewriteEngine On
rewritecond %{http_host} ^yoursite.com
rewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L]
于 2013-09-01T16:47:43.130 回答