php - Get drupal user session in Yii subdomain -
i have 2 sites, 1 parent site www.example.com (which developed in drupal) , other site subdomain, let app.example.com (which in yii ) user logged-in using drupal site , once logged-in, , can visit app.example.com , need detail of user in yii .
currently, yii::app()->user->isdrupalauthenticated() returns false if user logged in.
*before creating subdomain, accessing yii site using www.example.com/app working fine. creating problem
i have code in 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 default constructor inherited 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; } }
ok have solved issue enabling line in drupal settings file
$cookie_domain = '.example.com';
now can access drupal session in yii domain
Comments
Post a Comment