How can the use of $PHP_SELF in PHP code be improved for better security and compatibility?

Using $PHP_SELF in PHP code can pose security risks as it can be manipulated by attackers to perform cross-site scripting attacks. To improve security and compatibility, it is recommended to use $_SERVER['PHP_SELF'] instead. This will provide the same functionality while also ensuring that the variable is coming directly from the server environment.

$php_self = htmlentities($_SERVER['PHP_SELF']);