What potential security risks are associated with using $_SERVER["php_self"] in PHP code?

Using $_SERVER["PHP_SELF"] in PHP code can potentially expose your application to cross-site scripting (XSS) attacks. It is recommended to sanitize and validate the input before using it to prevent malicious scripts from being injected into your application. One way to mitigate this risk is to use htmlspecialchars() function to encode special characters before displaying the output to the user.

$php_self = htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES, 'UTF-8');
echo $php_self;