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

sidjoshi2907's avatar

Session lifetime for Different Subdomains

I have 2 subdomains in a single Project, So Want to set different Lifetime for each of them..!! Is it Possible?

'lifetime' => 180, 'lifetime2' => 300,

0 likes
3 replies
bobbybouwmann's avatar

You can use a middleware to set the session for a specific domain. Something like this:

public function handle($request, Closure $next)
{
    $urlParts = explode('.', parse_url($request->url(), PHP_URL_HOST));
        $subdomain = $urlParts[0];

        if ($subdomain === 'my-custom-subdomain) {
        Config::set('session.lifetime', 300);
        }

    return $next($request);
}

Please or to participate in this conversation.