I have Laravel 5.6 project, and I have main domain example.com
and many sub-domains by language: en.example.com
, de.example.com
...
When I am using this function to login user: Auth::login($user, true)
, it's saving user token in cookie, the problem it's saving only in my current sub-domain en.example.com
and when i change URL to de.example.com
I don't have this cookie.
I need this cookie to be shared between all the sub-domains and the main-domain.
I tried some solutions, but no one succeed.
-
Change
session.cookie_domain
in php.ini and with ini_set functionini_set('session.cookie_domain', ".example.com");
-
Change
domain
inconfig/session.php
from:
'domain' => env('SESSION_DOMAIN', null),
to:
'domain' => '*.example.com', -
And the worst problem, that I am not sure why it happens, is that I tried to set cookie with
.example.com
domain and it didn't work!\Cookie::queue('Test', 'Test', time()+60*60*24*365*5, '/', '.example.com');
and
setcookie('Test', 'Test', time()+60*60*24*365*5, '/', '.example.com');