What are some common solutions for handling access rights and permissions issues in PHP?

Access rights and permissions issues in PHP can be handled by implementing role-based access control (RBAC) or using access control lists (ACL). RBAC involves assigning roles to users and defining permissions for each role, while ACL allows for more granular control over individual resources. Example PHP code snippet for implementing RBAC:

// Define roles and permissions
$roles = [
    'admin' => ['create', 'read', 'update', 'delete'],
    'editor' => ['create', 'read', 'update'],
    'viewer' => ['read'],
];

// Check if user has permission
function hasPermission($role, $permission) {
    global $roles;
    return in_array($permission, $roles[$role]);
}

// Example usage
$userRole = 'admin';
$userPermission = 'delete';

if (hasPermission($userRole, $userPermission)) {
    echo 'User has permission to delete';
} else {
    echo 'User does not have permission to delete';
}