curl_init

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

curl_initEine cURL-Session initialisieren

Beschreibung

curl_init ( string $url = null ) : resource

Initialisiert eine neue cURL-Session und gibt einen cURL-Handler zurück, der mit den curl_setopt(), curl_exec(), und curl_close() Funktionen 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 ein cURL-Handle im Erfolgsfall zurück, false im Fehlerfall.

Beispiele

Beispiel #1 Abrufen einer Webseite

<?php
 
// erzeuge einen neuen cURL-Handle
 
$ch curl_init();
 
 
// setze die URL und andere Optionen
 
curl_setopt($chCURLOPT_URL"http://www.example.com/");
 
curl_setopt($chCURLOPT_HEADER0);
 
 
// führe die Aktion aus und gib die Daten an den Browser weiter
 
curl_exec($ch);
 
 
// schließe den cURL-Handle und gib die Systemresourcen frei
 
curl_close($ch);
 
?>

Siehe auch

add a note add a note

User Contributed Notes 1 note

up
1
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