Skip to content

Commit e25eee9

Browse files
akamiyadg
authored andcommitted
add support for basic auth for file_get_contents() in Feed::httpRequest() (#15)
1 parent 08622f4 commit e25eee9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Feed.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,19 @@ private static function httpRequest($url, $user, $pass)
220220
? $result
221221
: false;
222222

223-
} elseif ($user === null && $pass === null) {
224-
return file_get_contents($url);
225-
226223
} else {
227-
throw new FeedException('PHP extension CURL is not loaded.');
224+
$context = null;
225+
if ($user !== null && $pass !== null) {
226+
$options = array(
227+
'http'=> array(
228+
'method' => 'GET',
229+
'header' => 'Authorization: Basic ' . base64_encode($user.":".$pass) . "\r\n"
230+
)
231+
);
232+
$context = stream_context_create($options);
233+
}
234+
235+
return file_get_contents($url, false, $context);
228236
}
229237
}
230238

0 commit comments

Comments
 (0)