CodeIgniter Forums
CI4 Session returns null - 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: CI4 Session returns null (/showthread.php?tid=75068)



CI4 Session returns null - rahul.chandrasekharan - 12-16-2019

using CodeIgniter [i]version 4[/i] and trying to set a variable in session like

LoginController


Code:
$session = \Config\Services::session();
$session->set(['user_logged_in' => true]);

and redirecting the user to another page



Code:
return redirect()->to(base_url() . '/user');

but when tried to get the value of  `
user_logged_in`  it returns `null`

UserController

Code:
$session = \Config\Services::session();
$session->get('user_logged_in');

Tried using the native PHP methods, but still the session variable is getting null. Tried to start the session in constructor but it results in error


Quote:ini_set(): A session is active. You cannot change the session module's ini settings at this time


What would be the problem? Please help.
Thanks.