Laravel Session always changes every refresh / request in Laravel 5.4

后端 未结 6 757
春和景丽
春和景丽 2020-12-01 12:38

So the title basically says it all, I am using Laravel 5.4, PHP 7.1 and on my local machine sessions are working just fine. Essentially when trying to login or reloading the

相关标签:
6条回答
  • 2020-12-01 13:16

    I was also facing the similar problem in Laravel 5.6. My application was working and and never had issues regarding authentication. Suddenly I got a "419 | page is expired" error and the CSRF token was being generated with every single refresh.

    Finally I figured out that the browser had blocked the cookies set by the application. I still had not found a permanent fix but allowing or deleting those blocked cookies temporarily solved the issue.

    I have nothing changed in my config/sessions.php* configuration file and the application works fine in local server.

    0 讨论(0)
  • 2020-12-01 13:21

    I discovered this problem after two days The one you go to Select PHP Version inside Cpanel Change the option section and the selected version once and return to the previous state. By doing this, you will reset the memory of the session to be clean! Then it will be OK again.

    excuse me I do not know English well

    0 讨论(0)
  • 2020-12-01 13:23

    We got threw this error too, and this is what seems to fix the problem :

    • Check that your storage/ folder have the correct right

    • Try to disable all the Javascript in your pages (either by disabling it via navigator or inside the code) and make sure that 'http_only' => true,

    • Try to use with and without https

    • Make sure the SESSION_DRIVER variable is NOT null

    • Try to switch between 'encrypt' => false, and 'encrypt' => true,

    • Try to change the cookie name 'cookie' => 'laravelsession',

    • Try either to set your SESSION_DOMAIN to your actual domain OR null

    • Try to switch between 'secure' => env('SESSION_SECURE_COOKIE', false), and 'secure' => env('SESSION_SECURE_COOKIE', true),

    After every step, this bug seems to be fixed, but somehow, the cookie still is not set in the navigator sometime until we use https on development too.

    I am sorry not to be able to provide a 100% fix, but having the EXACT same issue, I wanted to share my experience with you.

    0 讨论(0)
  • 2020-12-01 13:26

    Primary cause of this problem is laravel's inability to save session data on server side.

    With file as session storage, it can be & usually is a permissions issue, [Check SELINUX if you are on centos], laravel (that means apache or nginx or whatever user your process runs with) should have read and write permission on the folder where session files are stored [That is usually project root/storage folder].

    Another reason this can happen is when you are using database as a session storage and created sessions table manually and made the mistake of making id column of type bigint(20) or any other mismatching column.

    That again means laravel couldn't store the session data. Check my detailed answer about that here https://stackoverflow.com/a/45340647/7260022

    And the last point is about cookie and domain setting as mentioned above. Hope that helps to pinpoint the problem for anyone struggling with the issue in future.

    0 讨论(0)
  • 2020-12-01 13:29

    Disable nginx cache if you use it. For me it solved the same problem.

    0 讨论(0)
  • I found the solution to this was 2 parts, not sure why it varied since it was the same OS and setup.

    Step 1 make sure that COOKIE_DOMAIN is set properly and with no port numbers (Either in .env or directly in /config/session.php, whichever you use)

    Step 2 make sure that the cookie name ( 'cookie' => 'whatever') inside of /config/sessions.php does NOT have an underscore in it. Laravel apparently has had issues with this.

    0 讨论(0)
提交回复
热议问题