What is the best way to create a warning page for external links in PHP?

When creating a warning page for external links in PHP, you want to ensure that users are aware they are leaving your site and potentially entering a different domain. One way to do this is by creating a custom warning page that displays a message informing users about the external link and giving them the option to proceed or go back.

<?php
// Check if the link is external
if (strpos($_GET['url'], 'yourdomain.com') === false) {
    // Display a warning message
    echo "<h1>Warning: You are leaving our site</h1>";
    echo "<p>You are about to be redirected to an external website. Are you sure you want to proceed?</p>";
    echo "<a href='{$_GET['url']}'>Yes, proceed</a> | <a href='javascript:history.back()'>No, go back</a>";
} else {
    // If the link is internal, redirect the user
    header("Location: {$_GET['url']}");
    exit();
}
?>