How can PHP be used to ensure that only the logged-in user's profile is updated and not another user's?

To ensure that only the logged-in user's profile is updated and not another user's, you can include a check in your PHP code to compare the user ID of the profile being updated with the user ID of the currently logged-in user. If they do not match, the update should not be allowed.

// Check if the logged-in user is trying to update their own profile
if ($_SESSION['user_id'] != $profile_user_id) {
    echo "You do not have permission to update this profile.";
    // Redirect or display an error message as needed
    exit;
}

// Proceed with updating the profile
// Your update code here