开发者

Calling session_write_close() before Zend_Session::start() in the bootstrap causes an error

So I need access to an existing Session from Zend. Don't ask why, I don't like to talk about it. Anyway, I've gotten as far as discovering that I can access it from the bootstrap before I initialize my session. I have the following code in place to attempt to pull it out and transfer it over:

 protected function _initSession() {
        session_start();
        $values = $_SESSION;
        session_write_close();

        $db = Zend_Db::factory('Pdo_Mysql', array(
            'host'        =>'localhost',
            'username'    => 'uname',
            'password'    => '******',
            'dbname'    => 'dbname'
        ));
        Zend_Db_Table_Abstract::setDefaultAdapter($db);


        $sessionConfig = array( 
            'name'           => 'Sessions',      
            'primary'        => 'sessionID',   
            'modifiedColumn' => 'lastModifiedTime',     
            'dataColumn'     => 'data',
            'lifetimeColumn' => 'lifetime'
        ); 
        $saveHandler = new Zend_Session_SaveHandler_DbTable($sessionConfig); 
        Zend_Session::setSaveHandler($saveHandler); 
        Zend_Session::start();

        $old = new Zend_Session_Namespace('OLD');
        $old->开发者_如何转开发;values = $values;
}

It's choking when it hits Zend_Session::start(), claiming that a session has already been started. But I've called session_write_close() to close the session and as far as I can tell from my google-fu there's nothing wrong with restarting a previously cosed session. So why is it choking? Is it something specific to ZF? Is there something more I need to do to close the session? What gives?


You just can't.

Foremost, as described in the ZF documentation :

Do not use PHP's » session_start() function directly. If you use session_start() directly, and then start using Zend_Session_Namespace, an exception will be thrown by Zend_Session::start() ("session has already been started").

So your code must looks like that :

    Zend_Session::start();
    $values = $_SESSION;
    Zend_Session::writeClose();

But in Zend/Session.php:418, we have :

    if (self::$_sessionStarted && self::$_destroyed) {
        require_once 'Zend/Session/Exception.php';
        throw new Zend_Session_Exception('The session was explicitly destroyed during this request, attempting to re-start is not allowed.');
    }

So, the way you do the things is unsupported by ZF (like suggested : either with two different requests or with a batch script).


I face same issue today, so I read your blog but still did research , so I find a way which I am sharing with you.

Just use php "session_start()" rather then "Zend_Session::start();"

"Zend_Session::start();" doesn't work after session close so you can go with php session_start();

If you find any good solution please update me :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜