Tounu
Tounu

Reputation: 563

ZF2 : Trouble with session for authentication

I have a strange problem with the session after an authentication.

The whole authentification part works, troubles come after that :

        $result = $this->getAuthService()->authenticate();

            if ($result->isValid()) {
                $storage = $this->getAuthService()->getStorage();
                $storage->write(($this->getAuthService()
                        ->getAdapter()
                        ->getResultRowObject(array(
                                'email_utilisateur',
                                'password_utilisateur',
                            ))));
                $redirect = 'success';                    
            }

Right now, I am logged, and email+password are stored, in the "Zend_Auth" key (don't pay attention to the fact that I store password btw, it's for the example ^^).

But when I go on another page (even if it's the same), my Session key "Zend_auth" gets broken, and I have an incomplete PHP object....

Array
(
     [__ZF] => Array
         (
             [_REQUEST_ACCESS_TIME] => 1369667659.7526
         )

     [Zend_Auth] => __PHP_Incomplete_Class Object
        (
            [__PHP_Incomplete_Class_Name] => Zend\Stdlib\ArrayObject
        )

)

So, any idea why changing page would screw my session variable ?

Thanks in advance, I've spent like 5 hours on this problem, testing things etc...

EDIT 28/05/2013 :

So, I still didn't find. Anyway, the object that gets corrupted is a Zend\Stdlib\ArrayObject. A reason why this arrayobject gets corrupted would be that the session starts before the inclusion avec Zend\Stdlib\ArrayObject. I'll try to figure it out, but if that's the reason, then it's a bug of the framework. By the way, I'm using ZF 2.2.

Upvotes: 0

Views: 1463

Answers (1)

Tounu
Tounu

Reputation: 563

I FOUND ! So, as said, the reason was that the session started before the ArrayObject thing was known by the application. And, as you can read there :

https://zf2-docs.readthedocs.org/en/latest/modules/zend.session.advanced-usage.html

**Do not enable PHP‘s session.auto_start setting. If you do not have the ability to disable this.**

And that was the thing. session.auto_start was enabled in my php.ini. In order to fix this, you must set it to 0 in your php.ini file :

php_value session.auto_start 0

If your PHP is used for several applications/sites, then add this line to your .htaccess instead :

php_value session.auto_start 0

This will override the actual value of the php.ini

Hope it will help someone ^^.

Upvotes: 2

Related Questions