views:

253

answers:

2

I've two subdomains. Each subdomain has its own authenticated users database. I'm using

$auth = Zend_Auth::getInstance();
if($auth->hasIdentity()){ }

to check user login credentials. It works prefectly for each individual subdomain. But when I log into one subdomain and try to access 'restricted' page in another subdomain without logging out from first subdomain, it takes me thru. Basically 'auth' session of first subdomain returns true in '$auth->hasIdentity()' for second subdomain. How can I solve this?

EDIT: Probably using different auth session names might solve it but since I'm sharing the code between these 2 subdomains, this is not feasible option.

+1  A: 

You should restrict the auth cookies to the current subdomain.

erenon
@erenon: could you please explain a bit? How can I do that?
understack
@erenon: do you mean I should simply save subdomain in cookie? But then it could be modified to access second subdomain? right?
understack
+1  A: 

do somewhere at top of your Bootstrap

protected function _initModifiedSession()
{
    if ($this->hasPluginResource('session'))
    {
        $resourcesOptions = $this->getOption('resources');
        $resourcesOptions['resources']['session']['cookie_domain'] = $_SERVER['HTTP_HOST'];
        $this->setOptions($resourcesOptions);
        $this->bootstrap('session');
    }
}

UPDATE1
without Zend_Application

    $sessionOptions = array(
        'cookie_domain' => $_SERVER['HTTP_HOST']
    );
    Zend_Session::setOptions($sessionOptions);
SM
@SM: there is no class in my bootstrap file. Where should I put it?
understack
@SM: there are normal function calls in my bootstrap.php file. No class is defined there. I'm using it since version 1.6.5. Though I've upgraded to 1.9.
understack
@SM: ohh I see, you mean I should put in zend bootstrap class file?
understack
@SM: I tried to put into Bootstrap class inside zend/application/bootstrap/bootstrap.php file and called inside constructor but it never went inside 'if' condition.
understack
read zend_manual. bootstaping resources requeres config. application.ini with `resources.session.use_only_cookies = true` for example
SM