[Resolved] PHP - Fopen with https username and password

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
NamecheapNamecheap
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
PHP - fopen with https username and password

I am making a script that opens a text file on another website, copies the info from it, and then rewrites it to a text file on my server.

However the website that the text file is coming from is a https:// protocol and also has a username and password protection, a htaccess/password thing I would assume.

So waht I need is for the script to "log in" and then get the text file. if you get what I mean.

Is there any way I can do this?

Thanks
Tom
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I don't know about with fopen, but you can do it with cURL.

The two options you need to use are:
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 
0
Close
I am not 100% sure if it will work but you could try something like https://username:[email protected]/file.name

But as Dan points out curl would be a much better option.
 
0
Close
BTW:

I just added the two options I just mentioned to my cURL class.

PHP:
<?php

include('class.curl.php');
$curl->set_https();
$curl->set_userpass("user:pass");
$curl->get("http://msn.com");

?>
 
0
Close
filth@flexiwebhost said:
I am not 100% sure if it will work but you could try something like https://username:[email protected]/file.name

But as Dan points out curl would be a much better option.
You are correct. This is compliant with HTTP standards BTW.
Curl would be better if available and provides more control than fopen.
 
0
Close
I was trying that curl thing (which I'm not sure I fully understand)... but your lines give me this error dan:

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/tclayson/public_html/test/test.php on line 7

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/tclayson/public_html/test/test.php on line 8

Here is my script:
PHP:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $filename);
curl_setopt($ch, CURLOPT_USERPWD, "uname:pwd");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);

EDIT: Ok... I spotted the OBVIOUS mistake haha... and it works without errors now, but won't output anything to $return. I don't think its because the filename is wrong, or the username and password or anything, I've double checked them. Any ideas?
 
Last edited:
0
Close
You can use FOPEN for SSL sites by using ssl://site.com
 
0
Close
jerometan said:
You can use FOPEN for SSL sites by using ssl://site.com
erm... example? remember I need to put in a username and password as well.
 
0
Close
Use my cURL class (or rip parts out of it). I have tested it with logging in and https, and it works.
http://www.ruuma.com/s/class.curl.phps

PHP:
<?php

include('class.curl.php');
$curl->set_userpass("username:password");
$curl->set_https();
$data = $curl->get("http://thep.ag/e/you/want/to/get/here");
echo $data;

?>
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back