zendframework / zf1

This project reached its end-of-life on 2016-09-28. Contains conversion of ZF1 subversion repo to git, from version 15234 forward, and only containing master and release-1.12 branches and 1.12 tags.
https://framework.zend.com/blog/2016-06-28-zf1-eol.html
BSD 3-Clause "New" or "Revised" License
356 stars 799 forks source link

session_regenerate_id() issue on PHP7 #659

Open driesdroesbeke opened 8 years ago

driesdroesbeke commented 8 years ago

I have the following code that works on php 5.6 but throws a warning on PHP7. The session is not stored in the db with Zend_Session_SaveHandler_DbTable.

$session_handler = new Zend_Session_SaveHandler_DbTable ( $configSessionHandler );
Zend_Session::setSaveHandler ( $session_handler );

If (! Zend_Session::sessionExists ()) {
     Zend_Session::rememberMe ( $seconds );
     Zend_Session::start ( $config );
}

The rememberMe method calls self::regenerateId() wich causes the following error on PHP7

PHP Warning:  session_regenerate_id(): Session object destruction failed.  ID: user (path: /var/lib/php/sessions)
driesdroesbeke commented 8 years ago

Is fixed by #660

githoober commented 8 years ago

It was not fixed, the PR was declined.

ohcrider commented 8 years ago

same problem 2016-09-05 16 06 04

xorock commented 8 years ago

Is there any chance that someone will fix it before ZF1 EOL? I'm using lot of components from ZF1 and everything is fine under PHP7 except of Session.

driesdroesbeke commented 8 years ago

I wrote some tests that worked in vagrant but failed on Travis.

I worked around the issue by changing the order of the session bootstrap. Make sure a session exists before regenerateId() is called.

xorock commented 8 years ago

My code

public function _initZendSession() {
        $this->bootstrap('db');
        $this->bootstrap('session');
        Zend_Session::start();
        $defaultNamespace = new Zend_Session_Namespace();

        if (!isset($defaultNamespace->started)) {
            Zend_Session::regenerateId();
            $defaultNamespace->started = true;
        }
    }

And error is on line 320 of Zend\Session.php.

if (!self::$_unitTestEnabled) {
    session_regenerate_id(true);
}
GuillaumeRossolini commented 7 years ago

@driesdroesbeke the fix you suggested works by hiding the error message, but then the sid doesn't change when the user logs in (same cookie sid before and after they authenticate). Am I understanding this correctly?