curl_init

(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)

curl_initInicia sesión cURL

Descripción

curl_init(?string $url = null): CurlHandle|false

Inicia una nueva sesión y devuelve el manipulador curl para el uso de las funciones curl_setopt(), curl_exec(), y curl_close().

Parámetros

url

Si se proporciona, se estabecerá en el valor de la opción CURLOPT_URL. Se puede establecer manualmente esta opción usando la función curl_setopt().

Nota:

El protocolo file es deshabilitado por cURL si open_basedir está establecido.

Valores devueltos

Devuelve un manipulador de cURL si todo fué bien, false si hay errores.

Historial de cambios

Versión Descripción
8.0.0 En caso de éxito, esta función devuelve una instancia CurlHandle ahora; anteriormente, se devolvía un resource.
8.0.0 url es ahora nullable.

Ejemplos

Ejemplo #1 Inicia una nueva sesión cURL y captura una página web

<?php
// Crea un nuevo recurso cURL
$ch = curl_init();

// Establece la URL y otras opciones apropiadas
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// Captura la URL y la envía al navegador
curl_exec($ch);

// Cierrar el recurso cURL y libera recursos del sistema
curl_close($ch);
?>

Ver también

add a note add a note

User Contributed Notes 1 note

up
0
webmaster at jamescobban dot net
3 years ago
On recent distributions CURL and PHP support for CURL have not been included in the main product.  In particular in recent distributions of Ubuntu Linux CURL and PHP support for CURL are not even available from the official repositories.  The steps to incorporate support are complex and require adding a non-standard repository.  It is therefore advisable for programmers to rewrite code to use the stream interface to access resources across the Internet.  For example:

```php
$opts = array(
        'http' => array (
            'method'=>"POST",
            'header'=>
              "Accept-language: en\r\n".
              "Content-type: application/x-www-form-urlencoded\r\n",
            'content'=>http_build_query(array('foo'=>'bar'))
  )
);

$context = stream_context_create($opts);

$fp = fopen('https://www.example.com', 'r', false, $context);

```

This stream support can also be accessed using the object-oriented interface of SplFileObject.
To Top