user938513
user938513

Reputation:

curl php authentication not working

i know there are alot of questions out there but none solved my problem

i have to authenticate with uername and password and used curl as

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "/example.domain/tmp");
curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
curl_close($ch);

but every time it just returns false.

I'm pretty new to using cURL so I could be making some beginner mistakes, but I'm confused as to why this isn't working at all.

Any help would be greatly appreciated!

Upvotes: 2

Views: 3724

Answers (1)

Astha
Astha

Reputation: 1734

you are missing return transfer which is set to 1

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

write it before your CURLOPT_USERPWD i.e

curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");

then it might work. see if it work.

Upvotes: 2

Related Questions