【问题标题】:Get drupal user session in Yii subdomain在 Yii 子域中获取 drupal 用户会话
【发布时间】:2014-06-05 14:23:37
【问题描述】:

我有两个站点,一个是父站点 www.example.com(在 drupal 中开发),另一个站点是子域,比如说 app.example.com (在 Yii 中) 现在用户使用 drupal 站点登录,一旦登录,它可以访问 app.example.com ,我需要 yii 中的用户详细信息。

目前, Yii::app()->user->isDrupalAuthenticated() 即使用户登录也总是返回 false。

*在创建子域之前,我使用 www.example.com/app 访问 yii 站点,它工作正常。但是现在它的创建问题

我在 yii 中有这段代码:-

class LoginController extends Controller {
    public $defaultAction = 'initialize';

    public function actionInitialize() {
                   $this->verifyDrupalUserIdentity();
    }

    private function verifyDrupalUserIdentity() {
                    new DrupalUserIdentity();
                    if (!Yii::app()->user->isDrupalAuthenticated()) {// check if user logged in
                              header('refresh:5;url=http://www.example.com');
                              Yii::app()->end();
                              exit;
                    }
          }

}



define('DRUPAL_ROOT', '/var/www/example');
define('BASE_URL', 'http://www.example.com/');

class DrupalUserIdentity extends CUserIdentity {
          /**
           * Overriding the default constructor inherited from CUserIdentity
           */
          public function __construct() {
                    $this->authenticate();
          }        
          public function authenticate() {

                    global $base_url;
                    $base_url = BASE_URL';
                    $currentPath = getcwd();
                    require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
                    require_once DRUPAL_ROOT . '/includes/errors.inc';
                    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
                    chdir($currentPath);

                    global $user;
                    $this->username = $user->name;
                    $this->_id = $user->uid;
                    new DrupalUser();
                    Yii::app()->user->setDrupalAttributes($user);
          }



}


class DrupalUser extends CWebUser {

          private $_attributes;

          public function setDrupalAttributes($attributes) {
                    $this->_attributes = $attributes;
          }


          public function getDrupalAttribute($att) {
                    if ($this->_attributes->$att) {
                              return $this->_attributes->$att;
                    }
          }


          public function isDrupalAuthenticated() {
                    if ($this->_attributes->uid > 0) {
                              return true;
                    }else
                              return false;
          }

      public function getId() {
                    return $this->_attributes->uid;
          }
}

【问题讨论】:

    标签: php session drupal yii drupal-7


    【解决方案1】:

    好的,我已经通过在 drupal 设置文件中启用一行来解决这个问题

    $cookie_domain = '.example.com'; 
    

    现在我可以在我的 yii 域中访问 drupal 会话

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-30
      • 2012-12-25
      • 1970-01-01
      • 2012-06-25
      • 2011-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多