We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

[Phalcon 4.0.0 Alpha 2] New Session generated in every page refresh

Hi there,

I am trying to test a project and prepare for 4.0- change a lot of stuff for migration. But... cant figure out how to fix session. (my security tokens cant pass, so.. find that issue)

My code for now is (depending of unit tests):

$session = new \Phalcon\Session\Manager();
$session->setOptions([
 'uniqueId' => 'test-id' 
]);

$session->setHandler(new \Phalcon\Session\Adapter\Files());
$session->start();

return $session;

And still session is new every refresh - cant store nothing. Is any ideas?

PS: i am using latest 4.0.0 alpha 2 for Windows

You should check firstly browser's request/repsonse headers to check if cookie set correctly on HTTP level. After that You should dig into Phalcon stack

edited Feb '19

Well... checked. Yes. Its a project already works on 3.x version and try to prepare it for v4.

Check this simple php file too:

session_start();
$_SESSION['bobi'] = 'yeye';

if (isset($_SESSION['bobi'])) {
    echo 'YES';
} else {
    echo 'NO';
}

And comment second line after first execute- so i have worked session. But still in phalcon4 did refresh every request. If return to v3 no issues.



1.2k
Accepted
answer

I found solution for me... in changelog file for v4 is info about:

Fixed Phalcon\Session\Manager to not interact with $_SESSION variable if the session has not been started

So... i just added session_start... and all works fine.

        $di->set('session', function () use ($config) {
                session_start();

                $session = new \Phalcon\Session\Manager();
                $session->setOptions([
                    'uniqueId' => 'test' 
                ]);

                $session->setHandler(new \Phalcon\Session\Adapter\Files());

                $session->start();

                return $session;
        });

That's weird, session_start() shouldn't be necessary here really, if it is then it's a bug.

Try maybe to use setShared.