What are some common pitfalls when using PHP_SELF in a script?

One common pitfall when using PHP_SELF in a script is the potential for cross-site scripting (XSS) attacks. To mitigate this risk, it is recommended to sanitize user input before using it in the PHP_SELF variable. This can help prevent malicious scripts from being injected into the URL.

<?php
$current_page = htmlspecialchars($_SERVER['PHP_SELF']);
echo "Current page: " . $current_page;
?>