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

ruinobreferreira's avatar

Session not persisting after login, only with remember.

Hi everyone,

I'm losing authentication session after login. After authentication redirect I have all the auth info but I only need a single page refresh to lose the session. The session only persists if I set the remember to true.

Any clue? Anyone with a similar problem?

0 likes
15 replies
bashy's avatar

What are your settings in session.php and can you check the cookie expire time for us?

ruinobreferreira's avatar

Sorry... here goes.

session.cookie_lifetime=0

'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => null,
'secure' => false,
1 like
bashy's avatar

@nobreferreira You will need to mention me, I won't see the reply most of the time.

Thanks, what SESSION_DRIVER are you using? Can you also check on the cookie in your browser (before expire) to what the expire time is?

Example

bashy's avatar

@drake24 That doesn't tell me what the environment variable SESSION_DRIVER is. What's the value of that? If there's not one, it will use "file".

drake24's avatar

@bashy

my cookie

Name: laravel_session Content: eyJpdiI6Inp3cEcxSnRHVW84dmRXVERnelc4OEE9PSIsInZhbHVlIjoibmJESVJGR0pJV0Vyc3huR2NnYUx0NWRjdXBBTGJUT1VWUFNDRFFUckoydW1KdnNcL093QVpQb3QxZGpJQ0ZTS25mQ09hVHFVMTcxdTUxZGNVcFpnTnZRPT0iLCJtYWMiOiJlY2RhMGU4ZGMwN2VlOTZlMjI4ZTcxZTA5YmRjMzU2ODYzMjNhZTRjOTI5YzliNzA4MWI4MzgwZDZlYWExNTQwIn0%3D Domain: localhost Path: / Send for: Any kind of connection Accessible to script: No (HttpOnly) Created: Tuesday, July 21, 2015 at 5:27:59 PM Expires: Wednesday, July 22, 2015 at 10:06:59 AM

ruinobreferreira's avatar

Hey @bashy

Thanks a lot but it seems my problem is solved. I got back to the problem some days ago and adjusted some of my php.ini values and all seems ok for now. Sorry I forgot to update this issue.

Cheers.

drake24's avatar

@bashy file is still inside my storage/framework/session.

I don't understand this. It worked perfectly fine on Laravel 4

bashy's avatar

@nobreferreira Okay, no problem :) shouldn't have to edit anything from default settings in php.ini though.

@drake24 Not sure, there's so many things that can affect it. Have you got a L4 app on the same PHP environment to test?

drake24's avatar

@bashy Yes, I also copied the session setting in my Laravel 4.1 to 5.0 and still returns the same error

Nanod10's avatar

I had the same problem. The session only persisted if I ticked the box to remind me. I discovered that I had the session wrong. On the root of the domain I have an installation of L4, and in a folder I have an installation of L5. If I cleaned the cookies and went directly to the folder (L5) I logged in without checking the box to remind me, logged in and persisted until I accessed the domain root. This leads to several sessions, several XSRF-TOKEN.

The solution was to set the path of the cookie so that each cookie works independently. The domain configures it without www for example "example.com" (this will make it possible to use that cookie with and without www) (the cookie is set to ".example.com" automatically)

In short ... I post because this topic comes out in the search results and the friend above said I solve it in a way that I do not specify as ... then it is the same thing that did not say anything. It is my contribution translated with google translate

Please or to participate in this conversation.