What are the potential security risks associated with passing variables directly to HTML attributes in PHP?
Passing variables directly to HTML attributes in PHP can lead to potential security risks such as cross-site scripting (XSS) attacks if the input is not properly sanitized. To mitigate this risk, it is important to always sanitize and validate user input before outputting it to HTML attributes.
<?php
// Sanitize and validate user input before passing it to HTML attributes
$name = htmlspecialchars($_GET['name']);
echo "<p>Hello, $name!</p>";
?>