Zebra_cURL::http_authentication PHP Method

http_authentication() public method

the callback function to be executed for each and every request, as soon as a request finishes the callback function receives as argument an object with 4 properties (info, header, body and response) function mycallback($result) { everything went well at cURL level if ($result->response[1] == CURLE_OK) { if server responded with code 200 (meaning that everything went well) see http://httpstatus.es/ for a list of possible response codes if ($result->info['http_code'] == 200) { see all the returned data print_r('
');
            print_r($result);
show the server's response code
        } else die('Server responded with code ' . $result->info['http_code']);
something went wrong
($result still contains all data that could be gathered)
    } else die('cURL responded with: ' . $result->response[0]);

}
include the Zebra_cURL library
require 'path/to/Zebra_cURL';
instantiate the Zebra_cURL object
$curl = new Zebra_cURL();
prepare user name and password
$curl->http_authentication('username', 'password');
get content from a page that requires prior HTTP authentication
$curl->get('http://www.some-page-requiring-prior-http-authentication.com', 'mycallback');


If you have to unset previously set values use

$curl->http_authentication();
        
public http_authentication ( string $username = '', string $password = '', string $type = CURLAUTH_ANY ) : void
$username string User name to be used for authentication. @param string $password Password to be used for authentication. @param string $type (Optional) The HTTP authentication method(s) to use. The options are: - CURLAUTH_BASIC - CURLAUTH_DIGEST - CURLAUTH_GSSNEGOTIATE - CURLAUTH_NTLM - CURLAUTH_ANY - CURLAUTH_ANYSAFE The bitwise | (or) operator can be used to combine more than one method. If this is done, cURL will poll the server to see what methods it supports and pick the best one. CURLAUTH_ANY is an alias for CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM. CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM. Default is CURLAUTH_ANY. @return void
$password string
$type string
return void
    public function http_authentication($username = '', $password = '', $type = CURLAUTH_ANY)
    {
        // set the required options
        $this->option(array(CURLOPT_HTTPAUTH => $username == '' && $password == '' ? null : $type, CURLOPT_USERPWD => $username == '' && $password == '' ? null : $username . ':' . $password));
    }