Why is it recommended to use $_SERVER['PHP_SELF'] instead of $PHP_SELF in PHP scripts?

Using $_SERVER['PHP_SELF'] is recommended over $PHP_SELF in PHP scripts because $_SERVER['PHP_SELF'] is a predefined variable that contains the filename of the currently executing script. This helps prevent security vulnerabilities such as cross-site scripting (XSS) attacks that can occur when using user input directly in the script. By using $_SERVER['PHP_SELF'], you can ensure that the script's filename is sanitized and secure.

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