How does the use of $_SERVER['PHP_SELF'] in a link affect the functionality of a PHP code?

Using $_SERVER['PHP_SELF'] in a link can expose your code to potential security vulnerabilities such as cross-site scripting (XSS) attacks. To prevent this, you should sanitize the value of $_SERVER['PHP_SELF'] before using it in a link. One way to sanitize the value is to use htmlspecialchars() function to escape special characters.

$link = htmlspecialchars($_SERVER['PHP_SELF']);
echo "<a href='$link'>Link</a>";