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

silence's avatar

Laravel 5 creates a new session after each request

Hello I am working with the development version of Laravel 5 and I have a problem.

If I try this:

Session::set('hi', 'hello') dd(Session::get('hi'))

It prints "hello" but if I remove the set line and refresh the page it prints null

Also with the CSRF token it regenerates a different token every time I refresh the browser.

Native sessions ($_SESSION) do work so it is not a browser problem.

I am using file driver but I tried cookie driver and even "native" driver and it does not work.

Do you have any idea of what could be going on here?

Thank you.

0 likes
61 replies
henrique's avatar

I would say laravel is having trouble saving the session to ... well, I don't know the path to the sessions on laravel 5 (it is app/storage/sessions with laravel 4), check if there is any file and the permissions on that folder.

bashy's avatar

Laravel 5 sessions are stored in: /storage/framework/sessions

You will be able to see the sessions in there, if they are not, you may have a permission issue with that folder and Laravel can't write to it (hence, making new sessions).

silence's avatar

Hello, thank you for the help.

The folder is there and it has permissions

(By the way, I am using Laravel Homestead 2)

silence's avatar

It works if I manually call Session::save() so I guess there is a missing session save somewhere, I'm searching...

bashy's avatar

Always check that first before asking because we can't account for any missed changes :P

Checking a fresh install would help you narrow it down next time. If it works on fresh, you have an update which you didn't do.

1 like
Zini's avatar

I have the same problem using the last Laravel 5.0: Sessions are created- I can see the files appear in /storage/framework/session - but a new session is created at each request.

With this bug Laravel's sessions are useless, but also all components relying on them, such as the authentication or the flash messages. I did some research, and it seems I am not the only one with this issue.

sitesense's avatar

@Zini I think you should look elsewhere in your app :)

If it really was a bug in L5, this forum and Github would be FULL of complaints about it because L5 would be practically unusable, but it's not.

Take a look in /config/session.php... what is "lifetime" set to?

Zini's avatar

@sitesense You are probably right, also I am moving my app to a new Laravel insallation. I hope it will fix this issue.

In the meantime: this is the configuration of my sessions: 'lifetime' => 120,' expire_on_close' => false,

sitesense's avatar

@Zini your session config seems fine. Pre 4.1 some would have lifetime set to zero which caused probs upgrading to 4.1. Thought it might be something similar.

Have you tried deleting the cookies in your browser?

Zini's avatar

@sitesense Yes I have deleted the cookies and even used another browser, but the problem lasts: everytime I reload the auth page, a new session is created.

manu144x's avatar

I have the same issue and it's completely random, with different browsers and different computers even

manu144x's avatar

Ok, for me, I uninstalled the overbloated crap called Zend Server, (which doesn't work with composer either btw) installed WAMP with php 5.5 and now by magic everything works perfectly fine!

So it might be a server configuration issue too...

Zini's avatar

I installed Laravel again and moved my application inside: now the sessions work how they should. Unfortunately I have no clue where the problem came from.

@blackbird Homestead can be interesting for prototyping, but it is always better to have a local environment as close as possible to the production one.

jekinney's avatar

@Zini that in fact is what a vm (homestead) is. You can configure it exactly how your live server will be. If your production server runs an os and/or apache you can find another vm package for that os or create your own. Wamp or lamp stacks are quick and easy but you can't produce and test locally for those production environment nuances that use to frustrate developers.

jekinney's avatar

Quick question too. Nobody uses the built in PHP local environment? Every one seems to always reference some type of vm or web server stack. You guys know none of that is really required. You can download a database server (MySQL workbench includes a server) and just run php artisan serve. Boom, running web sever.

bashy's avatar

@blackbird Depends if you're going to host your site on Linux (and Ubuntu/Debian). Some host on CentOS/Red Hat and other distros. Some even IIS!

manu144x's avatar

After I finish my current projects, I will switch to that for sure, I heard really nice things about it and seems to be well supported with Laravel. I am new to Laravel btw.

irto's avatar

I'm getting the same problem. Laravel create a new session randomly.

bashy's avatar

@irto Test it on another server to narrow it down to causes.

irto's avatar

I did it and this error disappeared, only occurs in local.

bashy's avatar

@irto I would open another thread, if you want me to reply mention me with @bashy

Obviously something to do with your web server setup at local.

Paul_Fry's avatar

Hi,

I'm having exactly the same session issue. I'm using forge so can't be a server problem. Been stuck for hours.

Has there been any progress with this?

Paul_Fry's avatar

@bashy ha, I presumed forge was pretty solid? Is it not?

well, it's not working locally for me either. I'm going to try another fresh install but really confused as to why a new $sessionId would be generated on each page load.

If anybody has any other information i'd really appreciate it.

bashy's avatar

@Paul_Fry Well, it's good but it's just a VPS with a control panel. Things can go wrong :)

I'm not sure if this has been posted above because I don't want to read the thread again but are the sessions being written to file/database okay?

Paul_Fry's avatar

@bashy fairpoint :-)

yep, they are being written to db fine, however each page load is a new row, it never matches with any existing entries.

Next

Please or to participate in this conversation.