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

eliyas5044's avatar

How to solve auto logout problem in Laravel

Hi,

I have two projects running in the same shared hosting (Namecheap Reseller hosting), have SSH access. Laravel version is 5.4. In both projects, using database driver for session and cache. I have changed the cookie name for both projects. But I am facing two serious problems.

  1. It automatically logged out authenticated users after a few minutes.
  2. There is a blog part of it. If an authenticated user posts something, it showing another authenticated user posted it.

Please help me to solve this problem.

Thanks & Regards

0 likes
1 reply
MichalOravec's avatar

In your config/session.php you can incread lifetime, son in your .env file set SESSION_LIFETIME to higher number.

/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/

'lifetime' => env('SESSION_LIFETIME', 120),

'expire_on_close' => false,

How do you create your posts?

Auth::user()->posts()->create($request->all());

In view you have to show author of post

<span class="author">{{ $post->user->name }}</span>

You have propably there something like

<span class="author">{{ auth()->user()->name }}</span>

Please or to participate in this conversation.