0

Possible Duplicate:
How do I make a request using HTTP basic authentication with PHP curl?

I am using a PHP Curl Class from http://query7.com/php-curl and need to get content from one thrid party service provider with Basic Authentication.

I have no idea how I can pass my authentication details (i.e. username and password) to the above specified curl class.

1

2 Answers 2

2

Add the last line to your options array:

public $options = array(
    CURLOPT_RETURNTRANSFER => true,     // return the web page
    CURLOPT_HEADER         => false,    // don't return the headers
    CURLOPT_FOLLOWLOCATION => true,     // follow redirects
    CURLOPT_USERAGENT      => "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)", // set a normal looking useragent
    CURLOPT_AUTOREFERER    => true,     // set referer on redirect
    CURLOPT_CONNECTTIMEOUT => 120,      // timeout
    CURLOPT_TIMEOUT        => 120,      // timeout
    CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
    CURLOPT_USERPWD        => $username . ":" . $password // Basic auth
);
Sign up to request clarification or add additional context in comments.

1 Comment

Then you need to alter the class to allow you to add that optional parameter
0

Generally you can pass the username and password to the domain like this:

http://username:[email protected]/php-curl

Comments