Skip to content

Instantly share code, notes, and snippets.

@andrzj
Created October 4, 2017 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrzj/24df8f44cf29a52db00b354b7a084cae to your computer and use it in GitHub Desktop.
Save andrzj/24df8f44cf29a52db00b354b7a084cae to your computer and use it in GitHub Desktop.
PHP cURL with authorization
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $urlAuthComentarios,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_USERAGENT=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)',
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Basic ". base64_encode("$username:$password"),
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment