I've been reading up on (mysql) triggers the last few days... specifically what I'm trying to do is figure out a good methodology for updating a user's information.
The case use for this is related to a user management system:
Take for instance a admin
user updating a regular
user to a manager
, this user type
change would then enable|disable
software features on the interface.
Problem:
You won't know about this user type
change unless you query the database and reset say for example the $_SESSION['user']['type']
variable, and or the user logs-in|out of the system.
Question: Is there any good methodologies to solve this headache?
Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc). By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application.
What Are Session Variables? Session variables are special variables that exist only while the user's session with your application is active. Session variables are specific to each visitor to your site. They are used to store user-specific information that needs to be accessed by multiple pages in a web application.
Session variables are stored in associative array called $_SESSION[]. These variables can be accessed during lifetime of a session. The following example starts a session then register a variable called counter that is incremented each time the page is visited during the session.
Session global variables are either built-in global variables or user-defined global variables. The value of a database global variable is a single value that remains the same for all sessions that use this particular global variable.
I don't think mysql triggers would be ideal for this. Why? Because you will most probably end up with part of logic in php and part in mysql. It's a good thing to stay with one technology because it will be easier to maintain/debug code for you and your colleagues later.
So in your case, if you want the change of user role would take immediate action, you would have to either load user role on each script run or log out user using some flag in database that would signal that his session is not valid anymore (or you could implement your own session_set_save_handler
that would save session somewhere in file where you could delete it to log out user).
It depends on your needs which solution would better fits your case.
So it really depends on your needs to choose if it's better to log out user, give him new permissions right away or wait until next log in.
Question: Is there any good methodologies to solve this headache?
Find good reasons not to do it!
While this might sound like a joke, i am completely serious. You have to consider:
Someone who doesn't feel comfortable answering these questions doesn't really need that feature.
Find simple alternatives:
This is no laziness. Just focus on real value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With