简体   繁体   中英

Strange Zend_Session behaviour using Zend_Application

I'm writing to see if someone of you guys has encountered this problem before and have a chance to understand why it happened to me.

This is the story.

I developed many ZF applications before Zend Framework v. 1.8, then I've stopped for about 18 months. Now I had to start a new project on which I decided to use Zend Framework again.

On my local server I had the version 1.11.3 installed, so I didn't download the latest release.

Before the use of Zend_Application with the Bootstrap.php file I used to start sessions putting my session options in my config.ini file and then loading them into a Zend_Session instance like this:

config.ini

sessions.name = NAME
sessions.use_only_cookies = 1
sessions.save_path = APPLICATION_PATH "/../tmp/sessions"
sessions.strict = on
sessions.remember_me_seconds = 1800

index.php (into the public webserver directory) before starting the application:

Globals::startSession();

custom Globals class with various useful methods:

    class Globals
    {
            static public function startSession()
            {
            $sessions_conf = self::getConfig()->sessions;
            Zend_Session::setOptions($sessions_conf->toArray(););
            Zend_Session::start();
            }
    }

This has always worked very well, enabling my sessions (used with Zend_Session_Namespace) and storing the session files in the save_path.

With Zend_Application the manual tells to simply store the session options in the application.ini file under the "section" resources and Zend_Session will be configured automatically...

I did it like this:

; SESSIONS
resources.session.name = NAME
resources.session.use_only_cookies = 1
resources.session.save_path = APPLICATION_PATH "/../tmp/sessions"
resources.session.strict = on
resources.session.remember_me_seconds = 1800

It didn't worked. So I tried to use (not at the same time!) the _initSession() and _initForceSession() methods in the Bootstrap.php file, putting them at the beginning of the class and writing into them the code:

$this->bootstrap('session');

But session were never working, data were not stored between http requests and session files were never written into the save_path...

Could anyone, please, let me know if this is a normal behaviour (maybe I have missed something somewhere...)?

Obviously I solved the problem re-implementing my older method (and it works perfectly), but I would like to learn how to use it correctly.

Thanks in advance.

This should be a case of turn it on and it works, might have made it to easy.

I think you may have a problem with how you set your options in your application.ini:

; SESSIONS
resources.session.name = NAME
resources.session.name.use_only_cookies = 1
resources.session.name.save_path = APPLICATION_PATH "/../tmp/sessions"
resources.session.name.strict = on
resources.session.name.remember_me_seconds = 1800

according to the reference manual

To set a session configuration option, include the basename (the part of the name after "session.") as a key of an array passed to Zend_Session::setOptions().

with your options set correctly the bootstrap _initSession() should just work.

public function _initSession()
{
Zend_Session::start();
}

PS I use Zend_Session_Namespace all the time but rarely deal with a global session.

In your Bootstrap.php add

public function _initSession()
{
Zend_Session::start();
}

session options can be set in application.ini

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM