Login Customization
PHPMaker Tutorial Series
Hi All, Welcome To PHPMaker Tutorial Series
The website includes numerous pages that may display different layouts for various users. We need to align the available information in our website with the specific needs of each user. Some information must remain private, while other information needs to be publicly accessible.
Therefore, we need to manage the data and information according to the user’s category, referred to as the user’s role in PHPMaker.
Here’s the tutorial to customize user’s page according to users’ role :
1. Make Sure The User’s Table for Login is Active
click “Advanced” Button then make sure the user field level is associate with role column in users table
2. Make Sure Session Variable for roles is Exists
A web session refers to the period between when a user connects to a server and when the connection ends. Session variables 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. The session data is populated in a superglobal associative array $_SESSION. Session variables hold information about one single user, and are available to all pages in one application.
PHPMaker give us function to get current role name CurrentUserLevel(). If we call this function, it will return current role. Save it as Session variable so this value can be accessed across the website. But remember to logout and re-login after edit the session variable.
Click any table in PHPMaker then click the Code tab and find User_loggedIn.
copy paste this code on UserLoggedIn function
// User Logged In event
function User_LoggedIn($usr)
{
//Log("User Logged In");
$_SESSION['role'] = CurrentUserLevel();
}
save and re-generate the program.
3. Make the Rule
In example we have partnership table and we want to show the data based on user’s role in this table
we will show unilever and chefron to default user and PnG to exclusive user. Here’s the users data :
4. Filter The Data
After we put a role value to Session variable, let’s filter the partnership table with it.
to see further tutorials about filtering the table, you can see this tutorial.
5. Re-generate and Re-login
The result must be like this :
Users with role 0 or default user can access unilever and chefron data. meanwhile users with role 1 or executive can only access PnG data
If it doesn’t work, debug the session variable. Make sure roles is match with the filter.
Make Sure to re-login after changing the code.
That’s All. Happy learning!
References :
PHP Session — Tutorialspoint https://www.tutorialspoint.com/php/php_sessions.htm
PHP Session — W3School
https://www.w3schools.com/php/php_sessions.asp