CodeIgniter Forums
.env Settings ignored in session driver - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: .env Settings ignored in session driver (/showthread.php?tid=78661)



.env Settings ignored in session driver - korgoth - 02-22-2021

Hey guys i am having a very strange issue. 

My Config/App.php file is the default one, where the session driver is set as FileHandler. 

I would like to use a database for this, so i change my .env settings to:

Code:
app.sessionDriver = CodeIgniter\Session\Handlers\DatabaseHandler
app.sessionCookieName = sess
app.sessionSavePath = ci_sessions
app.sessionMatchIP = false
app.sessionTimeToUpdate = 300
app.sessionRegenerateDestroy = false

Unfortunately the application still uses the FileHandler, and not the DatabaseHandler

Things i have checked:
- the ci_sessions table is created via the migration;
- if i change the settings in Config/App.php to DatabaseHandler it seems to work (i can see data written to the ci_sessions table)
- i used this to debug my settings:
PHP Code:
d(env('app.sessionDriver'));
d(config('App')->sessionDriver); 

And the results are:

Code:
env(...) string (44) "CodeIgniter\Session\Handlers\DatabaseHandler"
⧉Called from .../app/Controllers/Dashboard.php:18 [d()]
config(...)->sessionDriver string (40) "CodeIgniter\Session\Handlers\FileHandler"
⧉Called from .../app/Controllers/Dashboard.php:19 [dd()]


So it seems to me that my settings are in place. 

What am i missing where? Isn't .env always overriding the settings in Config/App.php?


RE: .env Settings ignored in session driver - iRedds - 02-22-2021

CI 4.1.1
env(...) string (44) "CodeIgniter\Session\Handlers\DatabaseHandler"
⧉Called from .../app/Controllers/Home.php:12 [d()]
config(...)->sessionDriver string (44) "CodeIgniter\Session\Handlers\DatabaseHandler"
⧉Called from .../app/Controllers/Home.php:13 [d()]


RE: .env Settings ignored in session driver - korgoth - 02-22-2021

I am using 4.1.1 too, and yet behavior is different. My question is how can i troubleshoot this?


RE: .env Settings ignored in session driver - iRedds - 02-22-2021

Replace your configs with the default configs. Maybe some setting affects this behavior.


RE: .env Settings ignored in session driver - tgix - 02-23-2021

Just a comment - I have had "strange" problems with env lately - https://github.com/codeigniter4/CodeIgniter4/issues/3992
I have stopped relying on the magic .env for many things and replaced with standard php getenv() in this way:

$this->default['password'] = getenv('CONFIG_RDS_PASSWORD', true);

I still set CONFIG_RDS_PASSWORD in my .env.