Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel creates a new session on every request

for some reason that I can't figure out my Laravel install has started created a new session file on every request! This renders the session useless and so I users can't stay logged in, csrf tokens don't match etc.

I'm using Laravel 5.2. It seems fine on my local environment but not on the live server

Does anyone have any clues on why this might have happened and how I can resolve it?

Thanks in advance

like image 764
nvaughan84 Avatar asked Apr 15 '16 20:04

nvaughan84


People also ask

What is session regenerate Laravel?

Laravel utilize basically the original session file store but acts a little bit different. Beside changing the directory they are saved, when you call the regenerate function it creates another session file and deletes the old one. You can see it the implementation Illuminate\Session\Store. php .

How do sessions work in Laravel?

Sessions are used to store information about the user across the requests. Laravel provides various drivers like file, cookie, apc, array, Memcached, Redis, and database to handle session data. By default, file driver is used because it is lightweight. Session can be configured in the file stored at config/session.

Is Laravel session unique?

Of course each user session is unique to that logged in user.

How do I override a session in Laravel?

You can create your own SessionServiceProvider , extending Illuminate\Support\ServiceProvider\SessionServiceProvider and override registerSessionDriver() in order to return a custom instance of the store class. Then comment the Illuminate\Support\ServiceProvider\SessionServiceProvider in config/app.


1 Answers

Locally everything worked, but not on the production server. The problem was in the php.ini settings on the hosting, by default the parameter (variable) "mbstring.func_overload = 2" was set there. I removed it and than all worked. This parameter is for previous versions (PHP) which is used by many CMS. And Laravel gave an error 419 during authorization and nothing more, and created a new session every time the page was updated.

like image 195
Ivan Kovalenko Avatar answered Oct 08 '22 11:10

Ivan Kovalenko