What are the potential pitfalls of using the fopen function to redirect to a different URL within an IF statement in PHP?

Using the `fopen` function within an IF statement to redirect to a different URL in PHP can lead to potential security vulnerabilities, such as open redirect attacks. To prevent this, it is recommended to use header redirection instead of `fopen` for URL redirection.

if ($condition) {
    header("Location: https://example.com");
    exit();
}