Skip to content

Commit

Permalink
add support for basic auth for file_get_contents() in Feed::httpReque…
Browse files Browse the repository at this point in the history
…st() (#15)
  • Loading branch information
akamiya authored and dg committed Sep 24, 2019
1 parent 08622f4 commit e25eee9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,19 @@ private static function httpRequest($url, $user, $pass)
? $result
: false;

} elseif ($user === null && $pass === null) {
return file_get_contents($url);

} else {
throw new FeedException('PHP extension CURL is not loaded.');
$context = null;
if ($user !== null && $pass !== null) {
$options = array(
'http'=> array(
'method' => 'GET',
'header' => 'Authorization: Basic ' . base64_encode($user.":".$pass) . "\r\n"
)
);
$context = stream_context_create($options);
}

return file_get_contents($url, false, $context);
}
}

Expand Down

0 comments on commit e25eee9

Please sign in to comment.