What are the potential security risks associated with including files in PHP based on user roles?

Including files in PHP based on user roles can potentially expose sensitive information or functionality to unauthorized users if not properly secured. To mitigate this risk, it is important to validate the user's role before including any files and restrict access to files based on the user's role.

// Validate user role before including files
$userRole = $_SESSION['user_role'];

if($userRole == 'admin'){
    include 'admin_functions.php';
} elseif($userRole == 'user'){
    include 'user_functions.php';
} else {
    // Handle unauthorized access
    echo 'Unauthorized access';
}