curl_init

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

curl_initInicializar uma sessão cURL

Descrição

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

Inicializa uma nova sessão e retorna um identificador cURL para uso com as funções curl_setopt(), curl_exec(), e curl_close().

Parâmetros

url

Se fornecida, a opção CURLOPT_URL será definida com seu valor.Você pode definir isso manualmente usando a função curl_setopt().

Nota:

O protocolo file é desativado no cURL se open_basedir estiver definido.

Valor Retornado

Retorna um identificador cURL em caso de sucesso, false sobre erros.

Registro de Alterações

Versão Descrição
8.0.0 No caso de sucesso, a função retorna uma instância de CurlHandle; anteriormente era retornado um resource.
8.0.0 url agora permite null.

Exemplos

Exemplo #1 Inicializando uma nova sessão cURL e buscando uma página da web

<?php
// Cria um novo recurso cURL
$ch = curl_init();

// Configura a URL e opções
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// Obtém os dados
curl_exec($ch);

// Fecha o recurso cURL e libera recursos interos
curl_close($ch);
?>

Veja Também

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