What are the potential security risks associated with allowing users to input URLs for external content, such as Facebook pages, on a website?

Allowing users to input URLs for external content on a website can pose security risks such as cross-site scripting (XSS) attacks, phishing attempts, and malware distribution. To mitigate these risks, it is important to validate and sanitize the user input before displaying or processing it on the website.

// Validate and sanitize user input for external URLs
$external_url = filter_var($_POST['external_url'], FILTER_VALIDATE_URL);

if ($external_url) {
    // Process the external URL
} else {
    // Handle invalid URL input
}