Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using file_get_contents to authenticate and access an htaccess protected file [duplicate]

I need to reach a foreign .php page protected by a regular .htaccess file (Auth type Basic, htpasswords etc...).

I'd like to send the user and password needed through the request. Is it possible? I would like to avoid cURL and all pecl_http dependent functions if possible...

like image 611
Sebas Avatar asked Feb 25 '14 01:02

Sebas


1 Answers

Off-hand, I believe you can use a context to do that:

$context = stream_context_create(array (
    'http' => array (
        'header' => 'Authorization: Basic ' . base64_encode("$username:$password")
    )
));
$data = file_get_contents($url, false, $context);
like image 103
bishop Avatar answered Oct 21 '22 20:10

bishop