基本用法(GET 請求)

cURL 是一種使用 URL 語法傳輸資料的工具。它支援 HTTP,FTP,SCP 和許多其他(curl> = 7.19.4)。請記住,你需要安裝並啟用 cURL 擴充套件才能使用它。

// a little script check is the cURL extension loaded or not
if(!extension_loaded("curl")) {
    die("cURL extension not loaded! Quit Now.");
}

// Actual script start

// create a new cURL resource
// $curl is the handle of the resource
$curl = curl_init();

// set the URL and other options
curl_setopt($curl, CURLOPT_URL, "http://www.example.com");

// execute and pass the result to browser
curl_exec($curl);

// close the cURL resource
curl_close($curl);