Unable to share session with subdomains with Laravel 4

I am trying to use Laravel on a host that has many subdomains. Only one subdomain will have a Laravel application, but I would like to share some things (for example, with the current user) through my own PHP session.

I edited the Laravel session configuration to work with subdomains by changing the domain value:

'cookie' => 'mydomain_session', 'domain' => '.mydomain.com', 

In another subdomain where Laravel is not working, I try to access the session as follows:

 session_name("mydomain_session"); session_set_cookie_params(0,'/','.mydomain.com',false,true); session_start(); 

but it does not work, if I try to repeat the variable $ _SESSION, it will be empty.

The strangest thing is that if I try to repeat session_id (), it will be the same in both subdomains.

Moreover, if I install the same script in the third subdomain, it will not be a problem in conjunction with a session with another non-laurel subdomain.

So what am I doing wrong? Am I missing something, or is Laravel not managing my own PHP session in the usual way?

Any help is appreciated!

+6
source share
3 answers

or does Laravel not manage its own PHP session in the usual way?

Right.

Insert this at the beginning of the routes.php file:

 Session::put('foo', 'bar'); die(print_r($_SESSION)); 

You will see that Laravel places sessions in a multidimensional array.

For me, the "foo" session is contained in $_SESSION['_sf2_attributes']

0
source

You should probably switch to JWT (Json Web tokens). Because of their design, they do not suffer from this problem.

Sample this article for more information: https://auth0.com/blog/2014/01/27/ten-things-you-should-know-about-tokens-and-cookies/

0
source

You can share the session between several subdomains in laravel by setting

 config(session.domain, '.example.com'); 

OR in the .env file

 SESSION_DOMAIN='.example.com' 
0
source

Source: https://habr.com/ru/post/954539/


All Articles