I’ve got a range of classes to manage a website. They’re all included via this script at the top of each page
“`
require_once ‘OOP/Dbh.php’;
foreach (glob(“OOP/*.php”) as $filename){
require_once $filename;
}
One of these is a Session Class (might change this to cookie) but it will work the same way. It gets, sets and returns sessions names/values. Such as logged in status, logged in user etc. Another class is a User Class which manages users.
One method is to look up a database and see if any given function is available to that user. That method is called $User->checkAccess($) where the $ relates to the corresponding function (1 if I was editing a user as per below).
I do this by:
Having a table “availableFunctions”” which will have a row functionId: 1, functionName: ‘Edit Users’. There’s also a “userFunctions” table which has functionId: 1, userId: 1. Going back up to the example above, in that function I do a SQL query, if the a row exists with my logged in UserID and the function I’m attempting to do, I get true and display the page otherwise false.
This works!
However, is there a way inside each function across my collection of classes where I can reference back and check them. This way I don’t forget any other forms/processes which use the same function.