I have a successful script in Node.js which manages to get content from a page which requires authorization, by mimicking the login process.
I now need to get content from the webpage for a slightly different purpose using PHP and have attempted to "convert" the script from Javascript to PHP, however no results from the page are displayed (meaning the authorization doesn't work).
Could someone help me switch the code from Javascript to PHP or let me know what's wrong with mt current code?
Javascript Node.js Authorization
var request = require("request");
var j = request.jar();
var cookie = request.cookie('entercookie');
j.setCookie(cookie, 'http://www.example.com');
var request = request.defaults({jar: j});
request.post('https://www.example.com/login', {useame: 'useame', password: 'password'}, function(err, res, body) {
makeRequest(100);
});
PHP Authorization
$homepage = 'http://authorizationpage.com';
$useame = 'useame';
$password = 'password';
$cookie = 'cookie';
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$useame:$password:$cookie")
)
));
$data = file_get_contents($homepage, false, $context);
echo $data;
As you can see, I've set the useame, password and cookie for the page (as I did in the Node.js scrpt), however it's not "authorizing" the user.
