How can the variable $_SERVER['PHP_SELF'] be utilized in PHP scripts?

The variable $_SERVER['PHP_SELF'] can be utilized in PHP scripts to retrieve the filename of the currently executing script. This can be useful for creating self-referencing forms, building dynamic URLs, or for security purposes to prevent form spoofing attacks.

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <!-- Form fields go here -->
    <input type="submit" value="Submit">
</form>