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

Solaiman Hossain's avatar

Is there any way to find out the Laravel default session die path URL in Laravel project?

Actually, I am trying to get the default Laravel session die path URL but I can't find the default Laravel session die path URL. Is there anyone who can help me to find out the default Laravel session die URL path?

0 likes
14 replies
Tray2's avatar

What do you mean?

Can you please clearify?

Solaiman Hossain's avatar

@Tray2 I meant that in Laravel project after passing a few duration Laravel projects automatically become session die if the user does not any work after session dies Laravel projects show return redirect to the login page. I want to just keep another URL instead of using the login URL that's it.

Tray2's avatar

@Solaiman Hossain In you .env file there is a parameter called SESSION_LIFETIME that tells how long a session can be inactive.

Solaiman Hossain's avatar

@Tray2 No, I actually want to get the URL after the session expired redirect to ('/') login page, where can I find the URL path?

Sinnbeck's avatar

@Solaiman Hossain if my answer wasn't what you were after, please explain a bit more

Solaiman Hossain's avatar

@Sinnbeck I applied inside protected function redirectTo($request) but I am getting an error

 protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
			// return route('login');
            return redirect('url_name');
        }
    }

After applying the above code getting an error message ERROR Message is: Header may not contain more than a single header, new line detected

Header may not contain more than a single header, new line detected //Error message

C:\xampp\htdocs\wms-with-master-app\vendor\symfony\http-foundation\Response.php
{
        // headers have already been sent by the developer
        if (headers_sent()) {
            return $this;
        }
 
        // headers
        foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
            $replace = 0 === strcasecmp($name, 'Content-Type');
            foreach ($values as $value) {
                header($name.': '.$value, $replace, $this->statusCode); // laravel error bold line
            }
        }
 
        // cookies
        foreach ($this->headers->getCookies() as $cookie) {
            header('Set-Cookie: '.$cookie, false, $this->statusCode);
        }
 
        // status
        header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
 
        return $this;
    }
Snapey's avatar

When your session expires, you are now a GUEST

When a GUEST tries to access a route that is protected by auth middleware, then they are redirected to the login route which is in the Authenticate middleware as @sinnbeck already linked above

Solaiman Hossain's avatar

@Snapey If I use : return redirect('url_name'); instead of return route('login'); I am getting an error Error is: Header may not contain more than a single header, new line detected

<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            //return route('login'); 
			 return redirect('url_name');
        }
    }
}

After applying this above code I am getting this error message:

Header may not contain more than a single header, new line detected //Error message

C:\xampp\htdocs\wms-with-master-app\vendor\symfony\http-foundation\Response.php
{
        // headers have already been sent by the developer
        if (headers_sent()) {
            return $this;
        }
 
        // headers
        foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
            $replace = 0 === strcasecmp($name, 'Content-Type');
            foreach ($values as $value) {
                header($name.': '.$value, $replace, $this->statusCode);  // laravel error bold line
            }
        }
 
        // cookies
        foreach ($this->headers->getCookies() as $cookie) {
            header('Set-Cookie: '.$cookie, false, $this->statusCode);
        }
 
        // status
        header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
 
        return $this;
    }
Solaiman Hossain's avatar

@Sinnbeck, Actually I want to redirect another website url like :

return redirect('https://laracasts.com/');

Is it possible?

Devi007's avatar

you can hit URL for example www.abc.com/logout

In case if you want to change redirection or something and you have Laravel basic setup you can find Laravel logout function in LoginController.php File Something like this

public function logout(Request $request)

public function logout(Request $request)
    {
        $user = auth()->user();
        activity($user->name)
            ->performedOn($user)
            ->causedBy($user)
            ->log('LoggedOut');
        $this->guard()->logout();
        $request->session()->invalidate();
        return redirect('/');
    }

Please or to participate in this conversation.