How can the error "HTTP request failed! HTTP/1.1 401 Authorization Required" be resolved when including files in PHP?

The error "HTTP request failed! HTTP/1.1 401 Authorization Required" occurs when the server requires authentication to access the file being included in PHP. To resolve this issue, you need to provide the necessary authorization credentials in the HTTP request headers when including the file.

<?php
$url = 'http://example.com/file-to-include.php';
$username = 'your_username';
$password = 'your_password';

$options = array(
    'http' => array(
        'header'  => "Authorization: Basic " . base64_encode("$username:$password")
    )
);

$context = stream_context_create($options);
$included_file = file_get_contents($url, false, $context);

echo $included_file;
?>