How can the Authorization Header be sent to the server in PHP using HTTP wrappers or fsockopen?

When sending an Authorization Header to the server in PHP using HTTP wrappers or fsockopen, you can set the header by using the "Authorization" key in the headers array for HTTP wrappers or by manually constructing the HTTP request with the Authorization Header for fsockopen.

// Using HTTP wrappers
$url = 'http://example.com/api';
$options = [
    'http' => [
        'header' => "Authorization: Bearer YOUR_ACCESS_TOKEN\r\n"
    ]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);

// Using fsockopen
$host = 'example.com';
$port = 80;
$authorizationHeader = "Authorization: Bearer YOUR_ACCESS_TOKEN\r\n";
$request = "GET /api HTTP/1.1\r\nHost: $host\r\n$authorizationHeader\r\n";
$socket = fsockopen($host, $port, $errno, $errstr, 30);
fwrite($socket, $request);
$response = '';
while (!feof($socket)) {
    $response .= fgets($socket, 1024);
}
fclose($socket);