How can PHP_SELF be used to handle URL manipulation in PHP?

PHP_SELF can be used to handle URL manipulation in PHP by allowing the script to refer to itself. This can be useful for creating dynamic URLs, form submissions, and redirecting users to different pages based on certain conditions. By using PHP_SELF, you can ensure that the script will always refer to itself, regardless of the current URL.

// Example of using PHP_SELF for URL manipulation
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Handle form submission
    // Redirect user back to the same page after form submission
    header("Location: " . $_SERVER['PHP_SELF']);
    exit;
}