What potential issues could arise if the URI scheme is added to a URL without proper validation in PHP?

Adding a URI scheme to a URL without proper validation in PHP can lead to security vulnerabilities such as open redirect attacks, where an attacker can trick users into visiting malicious websites. To prevent this, it is essential to validate the URI scheme before appending it to the URL.

$url = "https://example.com";
$scheme = "http://maliciouswebsite.com";

// Validate the URI scheme before appending it to the URL
if (in_array(parse_url($scheme, PHP_URL_SCHEME), ['http', 'https'])) {
    $url = $scheme . $url;
}

echo $url;