Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Henoc's avatar
Level 1

Same Session for two different projects in different folders (no subdomains)

I'm using Laravel 5x and I'm trying to have the user login from (for example):

https://dev.example.com/example_authentication/public/login (this is one instance of laravel)

and then when I access:

https://dev.example.com/mysecondwebsite/public (this is another instance of laravel) I can just call:

$user = Auth::user();

and then get if its a user, admin, its name, etc.

What I've tried is to add both on the .env file of example_authentication and mysecondwebsite

SESSION_DOMAIN='.example.com'

but the session does not persist.

any idea on what's happening?

UPDATE:

I'm using on the second laravel app

$user = Auth::user();

for some reason it's generating its own session, for the record both instances have the same:

 'cookie' => 'vanguard_session'
  the same APP_KEY
  the same SESSION_DRIVER
0 likes
2 replies
jlrdw's avatar

Each laravel application has its own sessions. Why would you want to use the same session in two separate laravel applications.

Henoc's avatar
Level 1

@jlrdw This is a third party web app I'm trying to add to my own project

this third party app is just the basic auth of laravel, mostly standard and it's going to be used globally across the server (currently using corePHP is working fine because I just use this:)

require DIR.'/../bootstrap/autoload.php'; $app = require_once DIR.'/../bootstrap/app.php';

$request = Illuminate\Http\Request::capture();

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); $kernel->pushMiddleware(\Vanguard\Http\Middleware\EncryptCookies::class); $kernel->pushMiddleware(\Illuminate\Session\Middleware\StartSession::class); $kernel->handle($request); $user = Auth::user();

Please or to participate in this conversation.