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

Session shared between two Phalcon applications

I have two Phalcon projects on my WAMP Server in the www folder:

/www/app1

/www/app2

I'm using the phalcon session bag service to manage users session I used the same service name in these two apps:

//same code for the app1 and app2
$dependencyInjector->set('userSession', function(){

    return new \Phalcon\Session\Bag('user');

});

But It seems that this session is shared between these two apps. When I login with the app1, I found myself logged in the app2 !

Is that a bug from Phalcon or because it's the same domain name (https://localhost) so the browser use the same cookie/session ?

You're using the same namepsace for both applications, so of course the session will be shared. If you want the session data to be separate, use a different bag namespace.



16.2k

Yes, its because you are using the same domain. You have a cookie in your browser that specifies the session id. Cookies have a domain parameter and you can also specify a cookie to share a domain by using .mysite.com instead of mysite.com. But yes you will (should) only have one session id for all apps on localhost. See here:

https://www.php.net/manual/en/function.session-set-cookie-params.php