I'm having a big trouble with Laravel that I cannot fix. Sometimes my login session in my App drops randomly. Here is my config/session.php file:
<?php
return [
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 300,
'expire_on_close' => false,
'encrypt' => true,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => null,
'secure' => false,
'http_only' => true,
];
It is expected to work for several minutes after login (session being set) but I have cases which it drops after 5 minutes.
The login is customized and I use the session setter like this:
Session::put("admin",$admin);
I have read that the problem might be with file read/write concurrency? I find a bit awkward because there is only one machine using that login.
EDIT: before asking, all my routes are inside middleware Web.
'lifetime' => 300,
300 seconds is 5 minutes
Have you tried a higher amount like 600? which is 10 minutes
To fix this bug please upgrade laravel to 5.3! I really didn't figure out what was the problem
Related
My web application has a strange/weird behaviour. Whenever i log-in into the apps, everything fine. After click few times menu, it gets logout. My apps is running well without any weird that behaviour in development local.
Route::group(['middleware' => 'auth'], function () {
Route::group(['prefix' => 'app','as' => 'app.'],function(){
......
i use default auth middleware from laravel. i also change session driver from file to database but still have a problem with that weird behaviour of logout. My applications used to put in the shared hosting, and right now moved into the cloud. I have no issue before in shared hosting. But after moving into the cloud this is what happens.
note: i also have try change the cookies name but still got nothing.
here is the config session file
<?php
use Illuminate\Support\Str;
return [
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => env('SESSION_LIFETIME', 120),
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => env('SESSION_CONNECTION', null),
'table' => 'sessions',
'store' => env('SESSION_STORE', null),
'lottery' => [2, 100],
'cookie' => env(
'SESSION_COOKIE',
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
),
'path' => '/',
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE'),
'http_only' => true,
'same_site' => 'lax',
];
This question already has answers here:
"The page has expired due to inactivity" - Laravel 5.5
(20 answers)
Closed 4 years ago.
I am struggling with the problem of the laravel session. This page works on the problem bases on the server, but when I moved it to the new one and changed the domain, during login or registration, I get an error
The page has expired due to inactivity.
Please refresh and try again.
I send the token correctly in the meta tag and in the form.
On the old server, the page still works correctly, when I downloaded files from it and uploaded to localhost, the same error occurs.
I've already dug all threads in various forums but nothing helped.
I am asking for help and thank you in advance.
<?php
return [
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => env('SESSION_LIFETIME', 120),
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'store' => null,
'lottery' => [2, 100],
'cookie' => env(
'SESSION_COOKIE',
str_slug(env('APP_NAME', 'laravel'), '_').'_session'
),
'path' => '/',
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),
'http_only' => true,
'same_site' => null,
];
You can except that route as below :
1) Please ensure that you have added {{ csrf_field() }} in form
or
2) Go to app\Http\Middleware\VerifyCsrfToken.php and Add below
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* #var array
*/
protected $except = [
'/job-listing','logout','apply-job' // Your routes
];
}
I got a problem with a random session expire in Laravel 5. I watched a lot of discussion on this subject, but no one solution does not work.
While I'm on the site and going through the pages, particularly on the page personal account, there is breakage of session and then redirect to the specified in the app/Http/Middlevare/Authenticate.php file path. Also deletes all by my other session variables. My SESSION_DRIVER is 'file', but others drivers has the same problem. There is some of my configs in session.php:
'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
'http_only' => true
I have a problem with Laravel authentication, I've already made a question about it here. After considering multiple things that could be wrong, I checked if there is something wrong with the sessions.
\Session::set('variableName', 1);
\Session::save();
var_dump(\Session::get('variableName'));
If I execute the above code in one HTTP request, get returns the value, but if I try \Session::get('variableName') in a different HTTP request it returns null.
My config/sessions.php:
return [
'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,
];
There are session file being created in storage/framework/sessions.
According to the docs, you need to make sure you are not using array as your session driver since:
Array sessions are stored in a simple PHP array and will not be persisted across requests.
I am working with laravel 5.1. After login the session is expired after several minute without logged out by user.
I found one solution to change the name of cookie in config/session.php laravel_session to lerevelsession by removing underscore.
My config/session.php file is:
return [
'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' => 'laravelsession',
'path' => '/',
'domain' => NULL,
'secure' => FALSE,];
What is the problem that i can't figured out?