views:

118

answers:

2

This seems simple, but I am stuck.

I am trying to use basic authentication using an API. I can use curl from the command line, but I can't figure out how to convert this to PHP and cookies.

Please help!

A: 

You will use the setcookie function, as shown in this tutorial.

http://www.learnphp-tutorial.com/Sessions.cfm

I don't see what cURL would have to do with cookies and authentication.

James Black
+3  A: 

Basic authentication and cookies are completely different things. If I understand correctly, you're trying to make a curl request using PHP. If you want basic authentication, do this:

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");

If you want a cookie:

curl_setopt($ch, CURLOPT_COOKIE, "name=value");
JW
I don't think he wants cookies. Asker should understand that with basic auth, you send the authentication stuff every time. I seriously doubt whatever API he is talking to wants to feed cookies to the client.
timdev