ConFoo Montreal 2026: Call for Papers

Voting

: min(eight, three)?
(Example: nine)

The Note You're Voting On

aruntechguy at outlook dot com
7 years ago
If you want to use Basic Auth while using get_headers(), use stream_context options below.

I am using HEAD method here, but please feel free to use GET also.

<?php
$targetUrl
= 'http or https target url here';
$basicAuth = base64_encode('username:password');

stream_context_set_default(
[
'http' => [
'method' => 'HEAD',
'header' => 'Authorization: Basic ' . $basicAuth
]
]
);
$result = get_headers($targetUrl);

print_r($result);

<< Back to user notes page

To Top