My recommended methodology would be to store the type each user in the database. The problems that arise if you decide to keep type as a session variable will be (among others):
As soon as the session ends, this information will be lost. Typically, sessions last 30 minutes, although you can change this as long as you want. However, if you create a session that lasts 1 month, then anyone who has access to this user's computer will be logged into the user account without the need to use any password .
You will not be able to use the powerful and advanced queries offered by databases (for example, MySQL, which uses SQL). If you store your information in sessions, you may find a way to search for 1-on-1 user information, but why reinvent the wheel? This is not an easy development of the database structure from scratch, so I would not recommend doing it.
As for your problems accessing the database after updating the information, I would not say that this information applies as soon as possible. Let's imagine the following examples:
one)
If the user is currently a manager and loads a website where he can do powerful actions, and immediately after that he drops to the level of a regular user, then the presence of this information in the database will work fine. If the user tries to use his credentials (this is not his), he will click a button that will send a request to the database to confirm its type . Database queries are very fast, so speed is not a problem. I would be more interested in the speed you need to get information from a session variable than from a database.
2)
If the user was on the page while he was a regular user, and on the page he became a manager , then he will be able to exercise his authority after updating the page. I mean, if you used sessions, and you wanted the page to automatically retrieve information using AJAX , and then update its settings on the page, which would consume much more server power than a simple update.
For a simple SELECT * FROM myTable WHERE id = 4 may take only 1 millisecond to execute in the database. Databases were specifically designed for their speed, so they prefer
HOWEVER , perhaps you do not have access to the database, and that is why you are looking for an alternative? Well, you're in luck! MySQLi is a database that uses only a file to store information. It was specifically designed for users who do not have many resources and has many features like MySQL.
Webeng
source share