Thursday, 22 August 2013

Authorize and access a document using cURL, PHP

Authorize and access a document using cURL, PHP

I can login successfully using my browser
https://username:password@www.some-domain.com/manager/login.php
over https and substituting username and password with my appropriate
details no problem. I'm trying to do it with a PHP script and cURL,
although I'm having some problems.
My script follows:
$username = 'me';
$man_passwd = 'mypassword';
$url="https://username:password@www.some-domain.com/manager/login.php";
$postdata = "username=".$username."&password=".$man_passwd;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
echo $result;
curl_close($ch);
Upon loading the above page in my browser, I'm expecting to be logged-in
and re-directed to the above website, however my script reports:
This server could not verify that you are authorized to access the
document requested. Either you supplied the wrong credentials (e.g., bad
password), or your browser doesn't understand how to supply the
credentials required. Web Server at some-domain.com
It's not the credentials as they are correct and me having logged in
previously without problems. Which leaves: your browser doesn't understand
how to supply the credentials required
could you advise me of my misconception?

No comments:

Post a Comment