curl_init

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

curl_initInitialisiert eine cURL-Session

Beschreibung

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

Initialisiert eine neue cURL-Session und gibt ein cURL-Handle zurück, das mit den Funktionen curl_setopt(), curl_exec() und curl_close() genutzt werden kann.

Parameter-Liste

url

Sofern angegeben wird die Option CURLOPT_URL mit dem entsprechenden Wert initialisiert. Diese Option kann auch manuell per curl_setopt() gesetzt werden.

Hinweis:

Das file-Protokoll wird von cURL deaktiviert, wenn open_basedir gesetzt ist.

Rückgabewerte

Gibt im Erfolgsfall ein cURL-Handle zurück, im Fehlerfall false.

Changelog

Version Beschreibung
8.0.0 Bei Erfolg gibt diese Funktion nun eine CurlHandle-Instanz zurück; vorher wurde eine Ressource zurückgegeben.
8.0.0 url ist jetzt nullable (aktepiert den null-Wert).

Beispiele

Beispiel #1 Initialisieren einer neuen cURL-Session und abrufen einer Webseite

<?php
// erzeuge ein neues cURL-Handle
$ch = curl_init();

// setze die URL und andere Optionen
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// führe die Aktion aus und gib die Daten an den Browser weiter
curl_exec($ch);

// schließe das cURL-Handle und gib die Systemressourcen frei
curl_close($ch);
?>

Siehe auch

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