Initializing admin module doesn't recognized logged in user, if admin is on other subdomain

I have the following code in front-end, to check if the user is logged in module admin as admin.





$u = Yii::app()->user;

if (is_object($u)) {

	// under re-initialization this might not exists, that's why the additional check

	$_stateKeyPrefix = $u->getStateKeyPrefix();

}


/*

 * We initilize admin module, and once this is done in Yii::app()->user we have the admin state.

 * We do the check to see if the admin is logged in.

 * In the end, we reset the state key prefix to its original value,

 * and this change changes Yii::app()->user to the state we had on front-end.

 */

$m = Yii::app()->getModule('admin');

if(Yii::app()->user->isGuest) exit('You must log in as admin first');


// other calls before this might have initialised other modules, who might have changed the prefix

if (is_object($u)) {

	$u->setStateKeyPrefix($_stateKeyPrefix);

}



this works fine to check if the current PC has a session in admin also, if the admin is on the same domain eg:

dev.domain.com/admin

but doesn’t work if the admin is setup as a subdomain

admin.dev.domain.com

What options I have here to verifiy properly if the user is logged in as admin?

If I’m not mistaken, Yii uses cookies / sessions to handle (keep) user data. And AFAIK sessions / cookies are NOT shared between domains and that is probably, why you can’t use it the way, you describe.

My guess is to look for an example like SSO (Single Sign On), which allows handling of users signed to different applications / pages / domains. There should be some extension for in repository and there are for sure some talks on the forum. Just search here (or google anywhere) for SSO acronym.

Cheers,

Trejder