How can PHP_SELF be a potential security risk in form actions?

Using PHP_SELF in form actions can be a security risk because it opens up the possibility of a cross-site scripting (XSS) attack. To mitigate this risk, it is recommended to use htmlspecialchars() function to sanitize the PHP_SELF variable before using it in the form action attribute.

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
  <!-- form fields go here -->
</form>