UARPC is a PHP library that provides a flexible and easy-to-use framework for managing user access control. It allows you to define roles and permissions, assign roles to users, and check if a user has a specific permission.
To install the library, use Composer:
composer require steinhaug/uarpcTo start using UARPC, you need to initialize the uarpc and UARPC_base classes:
require 'vendor/autoload.php';
// Initialize the uarpc class to ensure all required files are loaded
new uarpc(); // DB_PREFIX
// Create a new UARPC_base instance with a user ID
$uarpc = new UARPC_base($userID);Here's a simple example of how to use UARPC to manage roles and permissions:
// Create a new role
$roleID = $uarpc->roles->add('Administrator', 'This is the administrator role');
// Create a new permission
$permissionID = $uarpc->permissions->add('create-post', 'Allows a user to create a new post');
// Assign the permission to the role
$uarpc->permissions->assign($permissionID, $roleID);
// Assign the role to a user
$uarpc->roles->assign($roleID, $userID);
// Check if the user has the permission
if ($uarpc->havePermission('create-post', $userID)) {
echo 'The user has permission to create a post.';
} else {
echo 'The user does not have permission to create a post.';
}See the commit log for updates.
- Upgraded steinhaug/mysqli to v1.9
- Adding tests
- Updated readme.
- Added $GLOBALS['steinhaugUarpcDbPrefix'] for all classes.
- Fixed composer requirements.
- Added UserID parameter so it's possible to check against any user.
->havePermission(PermTitle, UserID),
- Moved Mysqli2 into seperate project
This project is licensed under the terms of the MIT License. Enjoy!
Kim Steinhaug, steinhaug at gmail dot com.
Sosiale lenker: LinkedIn, SoundCloud, Instagram, Youtube, X, Ko-Fi, Github, Gitlab
Generative AI lenker: Udio, Suno, Huggingface
Resurser og hjelpesider: Linktr.ee/steinhaugai, Linktr.ee/stainhaug, pinterest/steinhaug, pinterest/stainhaug