What potential issue can arise when setting the value attribute in hidden input fields in PHP?

Setting the value attribute in hidden input fields in PHP can potentially lead to security vulnerabilities such as cross-site scripting (XSS) attacks if the value is not properly sanitized. To mitigate this issue, always make sure to properly escape and sanitize any user input that is being set as the value of a hidden input field. This can be done using functions like htmlspecialchars() or htmlentities() to prevent any malicious scripts from being executed.

<?php
// Example of sanitizing user input before setting it as the value of a hidden input field
$user_input = "<script>alert('XSS attack!');</script>";
$sanitized_input = htmlspecialchars($user_input, ENT_QUOTES, 'UTF-8');
echo "<input type='hidden' name='hidden_field' value='$sanitized_input'>";
?>