Every time I refresh the browser a new file is created in the /sotrage/framework/sessions
the problem doesn't happen in my localhost but it happens on the public host ( Bluehost )
var_dump(session()->all());
results:
array(1) { ["_token"]=> string(40) "xNETyNoJaC0i9Fm9gIPX49rQQ4Kzz4Oac3iPz8K6" }
(with different _token on every page reload)
Edit
here's my config.session file (without comments)
<?php
return [
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'store' => null,
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),
'http_only' => true,
];
I've spent hours trying to solve this, any help will be appreciated.
Related
I just changed these two settings in .env file
.env file:
CACHE_DRIVER=memcached
SESSION_DRIVER=memcached
After that I cleared config and cache:
php artisan config:clear
php artisan cache:clear
I have two registered users which are logged in. User1 logged in non-private, User2 in private window. When I logged out with User1, than User2 was also logged out automatically.
But if I change the session and cache driver to "file", than it works correctly.
config/session.php
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/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', true),
'http_only' => true,
'same_site' => 'none',
config/cache.php
'stores' => [
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
],
'memcached' => [
'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
'sasl' => [
env('MEMCACHED_USERNAME'),
env('MEMCACHED_PASSWORD'),
],
'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
],
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100,
],
],
],
],
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),
We tried it on a production server and different devices, same thing happens.
Why does this happen?
Solution
Here is my logout function:
/**
* Logout
* #return RedirectResponse
*/
public function logout(): RedirectResponse {
Cache::flush();
Auth::logout();
return redirect(self::LOGIN_URL);
}
I cleared cache every time when i logged out, so, this was the "bug".
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',
];
When i login into my Laravel application and dont click the checkbox "Remember me" then i will get kicked out of my session everytime when i try to make a api request but i don't know why.
If i click the checkbox "Remember me" everthing works fine.
Here is my session config:
'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',
In my .env:
SESSION_DRIVER=redis
SESSION_LIFETIME=120
I can't find the error.
Any ideas?
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?