I have created the following PHP code long time ago and it works, but I don't understand, why base64_encode is working with 2 variables, which are put together, inside a string base64_encode("$user:$pass")?
I hope somebody can help me to understand it.
Here the complete code section:
$user = "username";
$pass= "password";
//HTTP options
$opts = array('http' =>
array(
'method' => 'GET',
'header' => array ('Authorization: Basic '.base64_encode("$user:$pass"))
)
);
//Do request
$context = stream_context_create($opts); // creates GET request with encoded password
$url = "http://www.myURL.com/subpage";
$list = file_get_contents($url, false, $context); // get xml info
"$user:$pass"is the same as$user . ':' . $pass.