두 개의 사이트가 있는데, 하나는 부모 사이트 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;
}
}
좋아, 드루팔 설정 파일에서 라인을 활성화하여이 문제를 해결했습니다.
$cookie_domain = '.example.com';
이제 내 yii 도메인에서 drupal 세션에 액세스 할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다