Login Customization

Paramita Daniswari
3 min readMay 27, 2024

--

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

Pict. 1. Choose the users table

click “Advanced” Button then make sure the user field level is associate with role column in users table

Pict 2. make sure the role had choosen

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.

Pict 3. Find User_LoggedIn Menu

copy paste this code on UserLoggedIn function

Pict 4. Edit User_LoggedIn 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

Pict 5. Pertnership Table

we will show unilever and chefron to default user and PnG to exclusive user. Here’s the users data :

Pict 6. Users Table

4. Filter The Data

After we put a role value to Session variable, let’s filter the partnership table with it.

Pict 7. Filter The Table
Pict 8. Write The Filter

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 :

Pict 9. Users With Role 0 or Default

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

Pict 10. Users With Role 1 or Executive

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

--

--

Paramita Daniswari
Paramita Daniswari

Written by Paramita Daniswari

Programming Enthusiast - The written words yearn for timeless wings

Responses (1)