What are the potential security risks of using PHP_SELF in form actions?

Using PHP_SELF in form actions can expose your application to potential security risks such as cross-site scripting (XSS) attacks and path traversal attacks. To prevent these risks, it is recommended to use htmlentities() function to sanitize the PHP_SELF variable before using it in form actions.

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