Authorization header php file_get_contents

Can someone explain to me why this authorization function for the private bitbucket repository works on my local computer (PHP Version 5.3.17 works), but does not allow my remote server (PHP Version 5.3.20 works)

I don’t get the error as such - I just get a β€œforbidden” response from the bitpack. But everything works fine from my local server.

function bitBucketConnect($url){ global $bitPassword; global $bitUsername; $context = stream_context_create(array( 'http' => array( 'header' => "Authorization: Basic " . base64_encode("$bitUsername:$bitPassword") ) )); // Make the request return file_get_contents($url, false, $context); } 
+7
source share
1 answer

Your proxy will reply that authentication is required. You can scratch your head and think "but I provide authentication!"

The problem is that the value of 'header' applies only to http connections. To authenticate a proxy server, you first need to extract the file from HTTP before the context is valid for use on FTP.

 <?php $opts = array('ftp' => array( 'proxy' => 'tcp://vbinprst10:8080', 'request_fulluri'=>true, 'header' => array( "Proxy-Authorization: Basic $auth" ) ), 'http' => array( 'proxy' => 'tcp://vbinprst10:8080', 'request_fulluri'=>true, 'header' => array( "Proxy-Authorization: Basic $auth" ) ) ); $context = stream_context_create($opts); $s = file_get_contents("http://www.example.com",false,$context); $s = file_get_contents("ftp://anonymous: anonymous@ftp.example.org ",false,$context); ?> 
+9
source

All Articles