Search code examples
phpzend-frameworkcookie-path

How can I limit a cookie to "/admin" on my domain?


How can I make the cookie session.cookie_path only available for the module "/admin/"?

Zend Framework Code:

// Se Login?
public static function isLoggedIn() {
    $namespace = new Zend_Session_Namespace('Zend_Auth');
    $namespace->setExpirationSeconds(60*5); //5 Minutos dura una session

    $namespace->cookie_path = '/admin/'

    return Zend_Auth::getInstance()->hasIdentity();
}

I can't get PHPSESSION to have the path set to '/admin/'. PHPSESSION always has the path set to '/' in the cookie. ;-(


Solution

  • typeoneerror is almost there. You're gonna want to use the setting "cookie_path" and not "cookie_domain"

    Example:

        Zend_Session::setOptions(array(
            'cookie_lifetime' => 0,
            'cookie_path'     => "/admin",
            'cookie_domain'   => ".test.com",
            'cookie_secure'   => false,
            'cookie_httponly' => true
        ));