What are the recommended methods for securely passing and handling data between PHP pages, especially when dealing with user-selected options in dropdown menus?

When passing user-selected options from dropdown menus between PHP pages, it is important to sanitize and validate the data to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One recommended method is to use PHP's built-in functions like htmlspecialchars() and mysqli_real_escape_string() to sanitize the data before storing or displaying it. Additionally, using sessions or cookies to securely pass data between pages can help protect sensitive information.

// Sanitize user-selected option from dropdown menu
$user_option = htmlspecialchars($_POST['dropdown_option']);

// Validate the option before using it
if (/* validation condition */) {
    // Handle the data securely
    // For example, store it in a session variable
    $_SESSION['selected_option'] = $user_option;
}