How can PHP be used to differentiate login capabilities and access privileges for end customers, order placers, and logistics providers within a single database?

To differentiate login capabilities and access privileges for end customers, order placers, and logistics providers within a single database, you can create a 'role' column in your user table that specifies the role of each user. Then, you can use PHP to check the role of the logged-in user and restrict access to certain pages or functionalities based on their role.

// Assuming you have a 'users' table with columns 'id', 'username', 'password', and 'role'
// Connect to your database
$connection = new mysqli('localhost', 'username', 'password', 'database');

// Check if user is logged in
if(isset($_SESSION['user_id'])) {
    // Get user's role from the database
    $user_id = $_SESSION['user_id'];
    $query = "SELECT role FROM users WHERE id = $user_id";
    $result = $connection->query($query);
    $row = $result->fetch_assoc();
    
    // Check user's role and redirect based on their role
    if($row['role'] == 'end_customer') {
        header('Location: end_customer_dashboard.php');
    } elseif($row['role'] == 'order_placer') {
        header('Location: order_placer_dashboard.php');
    } elseif($row['role'] == 'logistics_provider') {
        header('Location: logistics_provider_dashboard.php');
    } else {
        // Handle unauthorized access
        echo "Unauthorized access";
    }
} else {
    // Redirect to login page if user is not logged in
    header('Location: login.php');
}