How can PHP be used to redirect users to a disclaimer page before accessing external links in a forum?

To redirect users to a disclaimer page before accessing external links in a forum, you can use PHP to check if the link is external and then redirect the user to the disclaimer page before proceeding to the external link. This can help ensure that users are aware of any potential risks associated with external links.

<?php
// Check if the link is external
function isExternalLink($url) {
    return parse_url($url, PHP_URL_HOST) != $_SERVER['HTTP_HOST'];
}

// Redirect users to disclaimer page before accessing external links
function redirectExternalLinks($url) {
    if (isExternalLink($url)) {
        header("Location: disclaimer.php");
        exit();
    } else {
        header("Location: $url");
        exit();
    }
}

// Example usage
$link = $_GET['link']; // Assuming the link is passed as a GET parameter
redirectExternalLinks($link);
?>