Using cURL (in PHP) to access http s url is often not as simple as using the proper url. Usando onda (em PHP) para acessar http s url muitas vezes não é tão simples como usar o bom url. Using it for authentication is also not very clearly documented. Utilizá-lo para autenticação não é, também, muito claramente documentadas. This is a mini tutorial for both accessing https url’s as well as for http authentication. Este é um mini tutorial para ambos acessando https url's, bem como para autenticação http.

The following is a simple example which show the most common options you will ever need to use to access https url’s as well as for http authentication. O seguinte é um exemplo simples que mostram as opções mais comuns que você necessitará sempre de usar para acessar https url's, bem como para a autenticação HTTP.

// The usual - init a curl session and set the url / / O costume - init curl uma sessão e definir o url
$ch = curl_init(); $ ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, $base_url); curl_setopt ($ ch, CURLOPT_URL, $ base_url);

// Set your login and password for authentication / / Defina seu login e senha para autenticação
curl_setopt($ch, CURLOPT_USERPWD, ‘login:pasword’); curl_setopt ($ ch, CURLOPT_USERPWD, 'login: senha');

// You can use CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, / / Você pode usar CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE,
// CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE / / CURLAUTH_NTLM, CURLAUTH_ANY, e CURLAUTH_ANYSAFE
// / /
// You can use the bitwise | (or) operator to combine more than one method. / / Você pode usar o bitwise | (ou) operador de combinar mais de um método.
// If you do this, CURL will poll the server to see what methods it supports and pick the best one. / / Se você fizer isso, terá Curl sondagem do servidor para ver o que ele suporta métodos e escolher a melhor delas.
// / /
// CURLAUTH_ANY is an alias for CURLAUTH_BASIC | CURLAUTH_DIGEST | / / CURLAUTH_ANY é um apelido para CURLAUTH_BASIC | CURLAUTH_DIGEST |
// CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM / / CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
// / /
// CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | / / CURLAUTH_ANYSAFE é um apelido para CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE |
// CURLAUTH_NTLM / / CURLAUTH_NTLM
// / /
// Personally I prefer CURLAUTH_ANY as it covers all bases / / Pessoalmente, prefiro CURLAUTH_ANY, uma vez que abrange todas as bases
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt ($ ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

// This is occassionally required to stop CURL from verifying the peer’s certificate. / / Este é ocasionalmente necessárias para pôr termo a curl de verificação do certificado do peer.
// CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if / / CURLOPT_SSL_VERIFYHOST também têm que ser TRUE ou FALSE se
// CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a / / CURLOPT_SSL_VERIFYPEER está desativado (é o padrão é 2 - verificar a existência de uma
// common name and also verify that it matches the hostname provided) / / Nome comum e também verificar a compatibilidade com o nome de host fornecido)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false);

// Optional: Return the result instead of printing it / / Opcional: Devolve o resultado ao invés de impressão é
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);

// The usual - get the data and close the session / / O costume - obter os dados e encerrar a sessão
$data = curl_exec($ch); $ data = curl_exec ($ ch);
curl_close($ch); curl_close ($ ch);

Use the above as a template for your code to simplify your data access using cURL. Use o referido como um modelo para o seu código para simplificar o acesso aos dados usando sua onda.

PS. The challenge with cURL documentation in PHP is that it is hard to find what you need from hundreds of available options and without enough examples of common use cases. O desafio com a onda documentação em PHP é que é difícil encontrar aquilo que você precisa de centenas de opções disponíveis, e sem suficiente exemplos de uso comum casos. What is needed is a series of How-To’s like the mini-tutorial above. O que é necessário é uma série de Como-A's como o mini-tutorial acima.