What are some common methods for implementing access control in PHP web development?

Implementing access control in PHP web development involves restricting access to certain parts of a website or application based on user roles or permissions. This can be done by checking the user's credentials against a set of predefined rules before allowing them to view or interact with specific content.

// Check user role before allowing access to restricted content
if($user_role == 'admin'){
    // Display admin-only content
    echo "Welcome, admin!";
} else {
    // Redirect to login page or display an error message
    header("Location: login.php");
    exit();
}