CodeIgniter Forums
Where to store login information in codeigniter. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Where to store login information in codeigniter. (/showthread.php?tid=81833)



Where to store login information in codeigniter. - yoshi - 05-07-2022

Perhaps this is more of a web application topic than codeigniter.

When a user logs in, the session retains the user id, so I can retrieve the entity from the user table in the controller immediately after login as follows.

PHP Code:
// e.g. 'user' model
{
  ["id"]=> string(1"2"
  ["email"]=> string(19"[email protected]"
  ["username"]=> string(30"demo_teacher2"
  ["password_hash"]=> string(60"$2y$10$...."
    :
  ["deleted_at"]=> NULL
 


I have added a variable to "app\Controllers\BaseController" to retain the model data extracted from the login id even if I have moved some controllers.

Here is the problem.
When I move to another controller, the contents of this variable disappear.

With the School Business Management System, for example, the "school" you belong to will never change while you are logged in.

Therefore, I would like to make it a variable to be remembered while I am browsing, but the value of the "user" model and "school" model will disappear.

Should I extract the model I need from the session id each time in the constructor of each controller?


RE: Where to store login information in codeigniter. - ignitedcms - 05-08-2022

If you want variables to persist across the entire app save it in a session.


RE: Where to store login information in codeigniter. - yoshi - 05-08-2022

(05-08-2022, 12:55 AM)ignitedcms Wrote: If you want variables to persist across the entire app save it in a session.

thanks ignitedcms-san.

I will study 'session'


RE: Where to store login information in codeigniter. - InsiteFX - 05-08-2022

Yes as @ignitedcms mentioned above the Session is the place to save it,
but you could also create a variable in the BaseController and access it using
$this->variable.


RE: Where to store login information in codeigniter. - yoshi - 05-08-2022

(05-08-2022, 01:25 AM)InsiteFX Wrote: Yes as @ignitedcms  mentioned above the Session is the place to save it,
but you could also create a variable in the BaseController and access it using
$this->variable.
thanks, InsiteFX-san

I have more drawers to keep variables globally in my application.



RE: Where to store login information in codeigniter. - yasinbabaei - 05-25-2022

Take the output of the program once and take a screenshot for the servant and send it so that I can explain your problem