What potential pitfalls should be considered when using hidden fields or sessions to store and calculate price adjustments in a PHP application?

One potential pitfall when using hidden fields or sessions to store and calculate price adjustments in a PHP application is that they can be manipulated by the user, leading to potential security vulnerabilities or incorrect calculations. To mitigate this risk, it is important to validate and sanitize any input data, use server-side validation for price adjustments, and avoid storing sensitive information in hidden fields or sessions.

// Validate and sanitize input data
$priceAdjustment = filter_input(INPUT_POST, 'price_adjustment', FILTER_SANITIZE_NUMBER_FLOAT);

// Server-side validation for price adjustments
if (is_numeric($priceAdjustment)) {
    // Calculate adjusted price
    $adjustedPrice = $originalPrice + $priceAdjustment;
} else {
    // Handle invalid input
    echo "Invalid price adjustment";
}