-
-
Save sagormax/91135eef3138b74a79ed1eb9fd14a960 to your computer and use it in GitHub Desktop.
PHP - HTTP Request with Basic Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$username = "some-username"; | |
$password = "some-password"; | |
$remote_url = 'http://www.somedomain.com/path/to/file'; | |
// Create a stream | |
$opts = array( | |
'http'=>array( | |
'method'=>"GET", | |
'header' => "Authorization: Basic " . base64_encode("$username:$password") | |
) | |
); | |
$context = stream_context_create($opts); | |
// Open the file using the HTTP headers set above | |
$file = file_get_contents($remote_url, false, $context); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment