What are the potential pitfalls of using $_SERVER['REQUEST_URI'] to generate links in PHP?

Using $_SERVER['REQUEST_URI'] directly to generate links in PHP can lead to potential security vulnerabilities like XSS attacks or directory traversal. To mitigate these risks, it's recommended to sanitize the input and validate the URI before using it in your code. One way to do this is by using the filter_var() function with the FILTER_SANITIZE_URL filter.

$uri = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL);
echo "<a href='$uri'>Link</a>";