What potential pitfalls should be considered when verifying the validity of a link in PHP?

One potential pitfall when verifying the validity of a link in PHP is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To mitigate this risk, it's important to use functions like filter_var() with the FILTER_VALIDATE_URL filter to validate URLs.

$link = $_POST['link'];

if (filter_var($link, FILTER_VALIDATE_URL)) {
    // Valid URL, proceed with processing
} else {
    // Invalid URL, handle error
}