What are some best practices for handling conditional link opening in PHP?

When handling conditional link opening in PHP, it is important to check if the link exists before attempting to open it. This can prevent errors and improve the user experience. One way to achieve this is by using the `file_exists()` function to check if the file or URL exists before opening it.

$link = "https://example.com";

if (file_exists($link)) {
    header("Location: $link");
    exit();
} else {
    echo "Link does not exist.";
}