Laravel 5.2 fails to read the session cookie - laravel

I have a issue in my laravel applications, i'm using XAMPP test run my applications locally on windows machine.
My problem is that Laravel applications get's logout suddendly, this happens very often, if i refresh the same page like 4 , 5 times it get's logged off. but when i check the chrome dev tools Cookies, Laravel_session is still there.
Any idea as to why this could happen?, also, i don't get the same issue when it's hosted online.

May be the problem is with session driver. Because as you said that if i refresh the same page like 4 , 5 times it get's logged off, by default session storage is file and you 4-5 time request may messing it up. Here I'm not sure but this stuff may solve your issue.
Change SESSION_DRIVER=file to SESSION_DRIVER=database in .env
Create session migration with php artisan session:table artisan
code
Run composer dump-autoload to regenerates the list of all
classes
Run php artisan migrate to migrate.
NOTE: You can run single migration file by separate with subfolder

Related

Laravel 5.2 session lost after successful login, sometimes

When trying to access a protected route or just refreshing the page the session is lost, so I have to login again. What I don't understand is that sometimes this problem does not happen but most of the time it does and sometimes it takes more than 3 times of doing the login before I can finally access a protected route. This only happens in production. I have no idea but it started only after I moved my hosting to Cloudways and users start complaining.I have other Laravel app with version 5.4 on the same server without problems.
1- change your session driver value to database then the user's session will be stored inside your database, sessions table instead of file:
in your .env file set :
SESSION_DRIVER=Database
2- clean cache and config
php artisan config:clear
php artisan cache:clear

Why do I suddenly start receiving 502 responses from the server when writing to the session?

I am working on a webshop, where the cart is stored in a session. I noticed that after a certain amount of distinct items added to the cart, I start receiving 502-responses, when I want to add more (distinct items). I am using Laravel and the site is hosted via Laravel Forge (using Nginx). I am using cookies to store the sessions.
.env
SESSION_DRIVER=cookie
I found lots of suggested solutions, but none of them worked for me.
I have meanwhile found the solution to this problem (see answer below). I am asking this question not because I need help, but because I want to help others who struggle with this issue, since it cost me a lot of time.
Asking questions just to answer them yourself is actively encouraged according to this blogpost by one of StackOverflow's co-founders: https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/.
The fix for my problem was to choose a different session driver. The problem seems to be connected to the limitations of cookies as implemented by browsers: https://github.com/laravel/framework/issues/18112
So I switched to using files to store sessions.
.env
SESSION_DRIVER=file
But this did not work right away. It only started working after I ssh-ed into the server and ran these commands:
composer dump-autoload
php artisan config:clear
php artisan cache:clear
(Also, I cleared all cookies stored for this site in my browser.)

I am seeing old laravel site even after updating files

I have a website that uses vuejs as frontend and Laravel API in backend. Recently I updated my Laravel site it was working absolutely fine in my localhost. But the problem is when I upload my Laravel files to my hostinger.com hosting account it's not updating. It's displaying me old site but my database got updated and I was able to errors of the new site.
I tried these none of them seems to be working,
Cleared browser history and cache
Tried reuploading site again
I ran following commands
php artisan config:cache
php artisan route:cache
php artisan view:cache
npm run prod
Tried to use cmd command ipconfig/flushdns
Still, I was not able to solve the issue.
Have you tried refreshing your website with CTRL+F5 or CTRL+R ?

File session driver not working properly on production (Laravel on shared hosting)

When using session on my local environment all worked ok, but when I publish the site in a shared hosting I started noticing some strange behaviours in the app. After a while I realized it has to do with the session and specifically I noticed that when I was working on my local environment the storage/framework/sessions folder only had 1 file that keep updating on any change but then on production I start monitoring the same folder and I realized that on any change instead of updating the file (or creating a new one and deleting the other) it was creating a new file but also keeping the old files making the app start acting in a wrong way.
Is this normal or should it be only 1 file per session as it was in the local environment?
Update
After login the user the app ask to select the business they want to work and also they can change between business after, to store the business they choose I use the session and there is where the problem pop, after every change on that property of the session it creates a new session file without deleting the old one. Again when I do exactly the same thing locally it works but for some reason on the shared hosting it doesn't.
SOLUTION
After days of trying to figure it out, I just figure out the solution.
Instead of using the Global Helpers of Laravel for storing the data I did it throw the request and apparently that work it out.
So basically instead of doing this:
session('clienteElegido' => $client);
I change it for this:
$request->session()->put('clienteElegido',$client);
I still don't understand what's the difference and why it was working fine in my local environment and not in the share host but its working now like that so all good.
Thank you for all the quick replies.
Try clearning cache, route, config and view
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
and let's see if your session issue will be fixed.

How to solve Page Expired Due to Inactivity in Laravel

I am a PHP developer using Laravel framework and currently i have an application which is in production. The users are being forced to log in every time even if they just logged in in less than 2 mins and get the message The Page expired due to inactivity. This is causing me headache as the application is doing just fine in the development environment in my my local machine.
I have search for solutions but non is working for me including generating keys using php artisan command, clear cache,config,route and view, i have also tried to increase the number of minuted for the session to expire to up to 8 hours but the same issue still occurring.
I am actually stranded and don't know what to do else,please i need a help to get out of this.
Thanks in advance
Option 1:
Set session lifetime in .env file to SESSION_LIFETIME=120 (2 hours)
Option 2:
Try all of them.
composer dump-autoload
php artisan optimize
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
Option 3: if these have no effect add remember me checkbox on login form who save session token for long time

Resources