curl_init

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

curl_initInicjalizuje sesję cURL

Opis

curl_init ([ string $url = NULL ] ) : resource

Inicjalizuje nową sesję i zwraca uchwyt cURL dla funkcji curl_setopt(), curl_exec(), i curl_close().

Parametry

url

Jeżeli podano, opcja CURLOPT_URL zostanie ustawiona na tą wartość. Możesz ustawić adres ręcznie, używając funkcji curl_setopt().

Informacja:

Protokół file jest wyłączony przez cURL jeśli dyrektywa open_basedir jest włączona.

Zwracane wartości

Zwraca uchwyt cURL przy powodzeniu, FALSE w wypadku błędów.

Przykłady

Przykład #1 Inicjalizowanie sesji cURL i pobieranie strony

<?php
// stwórz nowy zasób cURL
$ch curl_init();

// ustaw URL i inne potrzebne opcje
curl_setopt($chCURLOPT_URL"http://www.example.com/");
curl_setopt($chCURLOPT_HEADER0);

// pobierz stronę i wyślij do przeglądarki
curl_exec($ch);

// zamknij zasób cURL, zwolnij zasoby systemowe
curl_close($ch);
?>

Zobacz też:

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