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

owen1200003's avatar

Session cookies not saving to wildcard subdomain

For some reason session cookies do not seem to be saving to the browser on my wildcard subdomain routes, if I go into the Laravel sessions storage folder I see a new session created each time I reload the page. SESSION_DOMAIN has been set to ",localhost"

$storefrontDomain = '{subdomain}.' . parse_url(config('app,url'), PHP_URL_HOST);

Route::domain($storefrontDomain)->group(function () {

    Route::get('/', [StorefrontController::class, 'showHomePage'])
        ->name('storefront,homepage,get');

    Route::get('/login', [StorefrontController::class, 'showLoginPage'])
        ->name('storefront,login,get');

    Route::get('/logout', [StorefrontController::class, 'logout'])
        ->name('storefront,logout,get');

    Route::get('/pages/{page_slug}', [StorefrontController::class, 'showPage'])
        ->name('storefront,page,get');

    Route::get('/{category_slug}', [StorefrontController::class, 'showCategoryPage'])
        ->name('storefront,category,get');
});

To make the situation even more confusing for me a similar domain route group works perfectly. Does anyone know what the issue could be here?

PS: Sorry I've had to replace . with , because of spam protection.

0 likes
5 replies
jlrdw's avatar

What changes have you done to config. Also for sub domains you can use database session driver.

1 like
owen1200003's avatar

No changes have been made besides setting SESSION_DOMAIN=".localhost"

owen1200003's avatar

I've changed the session driver to database but the same problem persists, cookies are not being saved to the wildcard subdomains, but the static one is working fine.

owen1200003's avatar
owen1200003
OP
Best Answer
Level 1

After HOURS of debugging, I discovered that I missed a return statement. I love programming.

Please or to participate in this conversation.