How can user permissions be managed effectively in PHP when allowing data changes by the person who entered it?

To manage user permissions effectively in PHP when allowing data changes by the person who entered it, you can implement a role-based access control system. This system will define different roles (such as admin, user, moderator) and assign specific permissions to each role. When a user enters data, their role will determine whether they have the permission to edit or delete that data.

// Check if the user has permission to edit/delete the data they entered
if($currentUserRole == 'admin' || $currentUserID == $dataEnteredByUserID){
    // Allow data changes
    // Your code to edit/delete data here
} else {
    // Display an error message or redirect the user
    echo "You do not have permission to edit/delete this data.";
}