I'm trying to fetch an image file from an IIS 7 server ruing some ASP code. The goal is to bypass authentication by including the useame and password in the URL. Without authentication, a user is redirected to a login page.
This URL-based authentication method (which was provided by the software vendor) works fine from a browser, or from wget on the CLI, but not from within PHP using either file_get_contents() or curl functions.
I've tried creating a stream context for file_get_contents() to include a Basic authentication header, in the hopes it would show up there, but no luck.
The ASP code it's getting caught on looks like this:
var authUser = String(Request.ServerVariables("AUTH_USER"));
if (!authUser) {
// ...
// redirect!
}
The PHP code I've tried looks like this:
$img = file_get_contents($base_url);
Or this: $stream = stream_context_create([ "http" => [ "header" => "Authorization: Basic " . base64_encode("$user:$pass") . "" ], ]); $img = file_get_contents($base_url, false, $stream);
Or this:
$ch = curl_init($base_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$img = curl_exec($ch);
Very standard stuff, but in all 3 cases I'm seeing $img populated with the login page HTML. So, why is AUTH_USER getting set by a browser or wget but not these PHP functions?
