How can PHP be used to restrict downloads to only occur from a specific server?

To restrict downloads to only occur from a specific server, you can check the `$_SERVER['HTTP_REFERER']` variable in PHP to ensure that the request is coming from the allowed server. This variable contains the URL of the page that referred the user to the current page, so by checking this value, you can restrict downloads to only occur when the request is coming from the allowed server.

$allowed_server = 'https://example.com';

if(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $allowed_server) !== false) {
    // Allow the download to proceed
    // Add your download logic here
} else {
    // Redirect or display an error message
    echo "Unauthorized access";
}