Using cURL (in PHP) to access http s url is often not as simple as using the proper url. El uso de enrollamiento (en PHP) para acceder url http s a menudo no es tan sencillo como utilizar la URL adecuada. Using it for authentication is also not very clearly documented. Su utilización para la autentificación tampoco está muy claramente documentada. This is a mini tutorial for both accessing https url’s as well as for http authentication. Este es un mini tutorial para acceder a ambos url https, así como para la autentificación 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. El siguiente es un ejemplo sencillo que muestran la opciones más comunes que usted necesitará siempre a utilizar para acceder a la url https, así como para la autentificación http.

// The usual - init a curl session and set the url / / La habitual - init curl un período de sesiones y fijar la 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 / / Establezca su nombre de usuario y contraseña para la autentificación
curl_setopt($ch, CURLOPT_USERPWD, ‘login:pasword’); curl_setopt ($ ch, CURLOPT_USERPWD, 'login: pasword');

// You can use CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, / / Puede utilizar CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE,
// CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE / / CURLAUTH_NTLM, CURLAUTH_ANY y CURLAUTH_ANYSAFE
// / /
// You can use the bitwise | (or) operator to combine more than one method. / / Puede utilizar el bitwise | (o) operador para combinar más de un método.
// If you do this, CURL will poll the server to see what methods it supports and pick the best one. / / Si usted hace esto, se Curl servidor de la encuesta para ver qué métodos soporta y elige la mejor.
// / /
// CURLAUTH_ANY is an alias for CURLAUTH_BASIC | CURLAUTH_DIGEST | / / CURLAUTH_ANY es un alias de CURLAUTH_BASIC | CURLAUTH_DIGEST |
// CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM / / CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
// / /
// CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | / / CURLAUTH_ANYSAFE es un alias de CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE |
// CURLAUTH_NTLM / / CURLAUTH_NTLM
// / /
// Personally I prefer CURLAUTH_ANY as it covers all bases / / Personalmente prefiero CURLAUTH_ANY ya que abarca todas las 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. / / Esto es a veces obligados a dejar de curl de verificar el certificado de pares.
// CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if / / CURLOPT_SSL_VERIFYHOST posible que también tenga que ser TRUE o FALSE si
// CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a / / CURLOPT_SSL_VERIFYPEER está deshabilitada (su valor por defecto es 2 - comprobar la existencia de un
// common name and also verify that it matches the hostname provided) / / Nombre común y también verificar que coincida con el nombre de host proporcionado)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false);

// Optional: Return the result instead of printing it / / Opcional: Regresa el resultado en lugar de imprimirla
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);

// The usual - get the data and close the session / / La habitual - obtener los datos y cerrar la sesión
$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 lo anterior como una plantilla para el código para simplificar el acceso a los datos utilizando el enrollamiento.

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. El reto con cURL documentación en PHP es que es difícil encontrar lo que necesita de cientos de opciones disponibles y sin suficientes ejemplos de casos de uso común. What is needed is a series of How-To’s like the mini-tutorial above. Lo que se necesita es una serie de How-To's como el mini-tutorial.