I need to build a proxy for a Flash Player project I'm working on. I simply need to make a HTTP GET request with HTTP-Basic authentication to another URL, and serve the response from PHP as if the PHP file was the original source. How can I do this?
With Basic Authentication, you pass your credentials (your Apigee account's email address and password) in each request to the Edge API. Basic Authentication is the least secure of the supported authentication mechanisms. Your credentials are not encrypted or hashed; they are Base64-encoded only.
A client that wants to authenticate itself with the server can then do so by including an Authorization request header with the credentials. Usually a client will present a password prompt to the user and will then issue the request including the correct Authorization header.
Basic Auth: The client sends HTTP requests with the Authorization header that contains the word Basic, followed by a space and a base64-encoded(non-encrypted) string username: password. For example, to authorize as username / Pa$$w0rd the client would send. Note: Base64 encoding does not mean encryption or hashing!
Marc B did a great job of answering this question. I recently took his approach and wanted to share the resulting code.
<?PHP $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); print($file); ?>
I hope that this is helpful to people!
Using file_get_contents()
with a stream
to specify the HTTP credentials, or use curl
and the CURLOPT_USERPWD
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With