Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the contents of an authenticated HTTPS page

Status
Not open for further replies.

davidchardonnet

Programmer
Mar 21, 2001
167
FR
Hello,

I have a login/password on a website that uses https. I want that my php page retrieves the contents of an authenticated page on that web site.

I know how to do this on a standard http page, but with a https I am clueless.

How can I do?

Thank you

David
 
does this not work

Code:
file_get_contents("[URL unfurl="true"]https://username:password@website.com/page.php");[/URL]
 
[shocked] That would be quite daft. Securing a page in SSL and then sending the username and password in plaintext for anyone to see. I think you want to read this and find some example implementations (just do a net search for the RFC number):

This really explains what happens. Basicly you do TWO calls: one returns a 401 Unauthorized and (usually) a challenge. The above link tells you how to respond to that challenge to get the content.



+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
i didn't expect it to be sent in open form. i assumed (perhaps wrongly) that specifying the https protocol wrapper would cause php to negotiate certificates with the remote site in the same way that a browser would.
 
assuming i'm wrong, then you still be able to achieve your goal using curl

Code:
$page = getPage('[URL unfurl="true"]https://mydomain.com/page.php',[/URL] 'myusername', 'mypassword);


function getPage($url, $username, $password){
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $page = curl_exec($ch);
 curl_close($ch); 
 return $page;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top